当前位置: 移动技术网 > IT编程>脚本编程>vue.js > antd vue 上传文件List的坑

antd vue 上传文件List的坑

2020年07月08日  | 移动技术网IT编程  | 我要评论

使用单文件上传时@change事件会至少触发两次,一次file.status=uploading,最后一次要么是done或者error,

 handleUpload1(info) {
      if (info.file.status === 'uploading') {
        this.loading = this.isUpload1 = true
        return
      }
      if (info.file.status === 'done') {
        this.loading = this.isUpload1 = false
        this.params.imgUrl1 = info.file.response.data.url
      }
    },

但是如果是需要上传显示一组文件,则需要保存文件的状态会给一个属性 :file-list="fileList"
这时候change事件只会触发一次(uploading),后来在github上看到解决方法
对于受控模式,你应该在 onChange 中始终随时跟踪 fileList 的状态,保证所有状态同步到 Upload 内

handleVideoUpload(info) {
   let { fileList } = info
   const status = info.file.status
   if (status !== 'uploading') {
   }
   if (status === 'done') {
   		this.videoUrlList.push({ uid: fileList[fileList.length - 1].uid, url: info.file.response.data.url })
   }
   this.fileList= [...fileList] //重点
},

最后一行是关键,无论file上传状态如何,filelist一定要同步,还有不能用return,要不然就没有回调了

本文地址:https://blog.csdn.net/zhhao1/article/details/107106890

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网