1. 前端使用框架
umi4 + antd pro-component
2. 遇到问题:
使用ProFormUploadDragger 组件上传文件, onChange方法内每个状态都会更新两次,控制台如下:
index.jsx:28 info: uploading
index.jsx:34 uploading: 测试1.txt
index.jsx:28 info: uploading
index.jsx:34 uploading: 测试1.txt
index.jsx:28 info: removed
index.jsx:28 info: removed
3. 解决:
增加防抖计时器
import {debouce} from lodash
onChange: debounce((info) => {
if (info.file.status === 'done' && info.file.response.isSuccess) {
message.success(`${info.file.name} 上传成功`);
} else if (info.file.status === 'removed') {
message.info(`${info.file.name} 清除成功`);
} else if (info.file.status === "uploading"){
console.log('uploading:', info.file.name);
} else {
message.error('文件上传失败');
}
}, 200),
name,beforeUpload不生效:ProFormUploadDragger组件name和beforeUpload都要写在fieldProps里面,参考:

组件做了层代理props,但代理了一部分,其他的props代理都靠的fieldProps来传递的
6786






