1、按照官网upload配置,对图片上传成功,但解析onChangge时候,上传的图片的response一直为undefined
2、想要的结果:react用了dva脚手架,所以数据状态统一在model内管理,所以需要对response进行解析拼装数据
3、代码:
<div className="clearfix">
<Upload
name="uploadFile"
action="/jsharer-web/Pic/upload"
listType="picture-card"
fileList={fileList}
onPreview={handlePreview}
onChange={handleChange}
>
{fileList.length >= 3 ? null : uploadButton}
</Upload>
<Modal visible={previewVisible} footer={null} onCancel={handleCancel}>
<img alt="example" style={{ width: '100%' }} src={previewImage} />
</Modal>
</div>
//采取官网配置方式解析file和filelist
function handleChange(info) {
console.log("info");
console.log(info);
let fileList = info.fileList;
console.log("fileList");
console.log(fileList);
fileList = fileList.slice(-2);
fileList = fileList.map((file) => {
console.log(file.response); //控制台输出undefined
if (file.response) {
console.log("#");//因为undefined所以进不来
file.url = file.response.url;
}
return file;
});
fileList = fileList.filter((file) => {
if (file.response) {
return file.response.status === 'success';
}
return true;
});
//同步model内fileList数据
// onChangeFileList(fileList);
};
4、截图数据
//上传图片成功返回数据
//fileList 控制台返回数据
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…