1、按照官网upload配置,对图片上传成功,但解析onChangge时候,上传的图片的response一直为undefined
2、想要的结果:react用了dva脚手架,所以数据状态统一在model内管理,所以需要对response进行解析拼装数据
3、代码:
{fileList.length >= 3 ? null : uploadButton}
//采取官网配置方式解析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 控制台返回数据 
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你这种方式是做成可控组件,调用onChange方法的时候,有更新就要改变fileList的状态,不然onChange方法只会被调用一次。类似代码可以写成: