antd上传组件remove删除自定义存储文件使用踩坑记录

需求:选择要上传的文件后,点击文件列表中的删除图标,调用remove,删除自定义存储文件链接数组中的对应数据

首先看一下官方文档:在这里插入图片描述因为我这里限制了只能上传一个文件,所以删除的时候将对应的fileList清空就行,remove绑定的方法不传参数时会默认将对应文件数据传递进去,我想直接传递一个参数,会覆盖掉默认传递的参数,然后直接操作我传递的参数,结果这样做报错了,remove绑定的事件直接触发了切告警会递归地触发自己,死循环了

错误代码:

<a-upload
   :accept="data.options.accept"
   :file-list="data.options._uploadModalFile"
   :before-upload="file => beforeTableUpload(file, data)"
   :remove="handleTableRemove(data)"
 >
   <a-button>
     <SvgIcon iconClass="fileupload" style="margin-right: 10px;" />
     点击上传
   </a-button>
 </a-upload>

告警信息:
在这里插入图片描述

修改后代码:

<a-upload
  :accept="data.options.accept"
  :file-list="data.options._uploadModalFile"
  :before-upload="file => beforeTableUpload(file, data)"
  :remove="file => handleTableRemove(file, data)"
>
  <a-button>
    <SvgIcon iconClass="fileupload" style="margin-right: 10px;" />
    点击上传
  </a-button>
</a-upload>

将data作为自定义参数传进去,这样就解决了。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

濮家大少

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值