解决使用ProFormUploadDragger组件 onChange会走两次的bug以及beforeUpload不生效

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来传递的
组件做了层代理props,但代理了一部分,其他的props代理都靠的fieldProps来传递的

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值