【实操】vue2项目中 vant Uploader组件删除时获取下标

场景:上传多个图片一起提交。图片上传时将接口返回的服务器图片链接存到了自定义的数组中,当删除时需要获取下标删除数组中相应的数据。

 <van-uploader
    v-model="fileList"
    :after-read="afterRead"
    multiple
    @delete="(file, detail) => deleteImg(file, detail)"
/>


  
 async afterRead(e) {
   let _this = this
   e.status = 'uploading'
   e.message = '上传中...'

   let fd = new FormData()
   fd.append('file', e.file)

   let res = await api.upLoadFile(fd)
   if (res) {
     if (res.resp_code === 0) {
       e.status = 'success'
       e.message = '上传成功'
       _this.imageList.push(res.datas.foreignPath)
     } else {
       _this.$toast(res.resp_msg)
     }
   } else {
     e.status = 'failed'
     e.message = '上传失败'
     _this.imageList.push('')
     return ''
   }

},

// 在 detail 中获取下标
deleteImg(file, detail) {
  this.imageList.splice(detail.index, 1)
},

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值