解决 element-ui upload Cannot set properties of null (setting ‘status‘)

element-ui upload组件多选文件上传改造

element ui 上传图片组件选择多图时报错 element-ui upload Cannot set property ‘status‘ of null

注意fileList是只读的,不能修改。我们这里使用uploadList来保存我们需要改动的数组,否则报错Cannot set property ‘status’ of null

问题分析:
每次上传都会促发 handleBeforeUpload和handleBeforeSuccess,传几张就会触发几次,经过反复调试,应该是handleBeforeSuccess上传回调方法执行多次$emit引起的

解决方案:
声明一个number变量用于记录上传图片数量,上传成功回调后通过判断图片数量与number一致时,执行一次$emit。
使用uploadList数组用来临时保存上传的多图数组

增加两个变量:
uploadList: [],
number:0

修改两个方法:

  1. handleBeforeUpload
	handleBeforeUpload(file) {
		...
      	this.number++;
    },
  1. handleBeforeSuccess
	handleUploadSuccess(res) {
      	//上传成功回调
      	this.uploadList.push({ name: res.fileName, url: res.data })
      	if(this.number==this.uploadList.length){
        	this.fileList = this.fileList.concat(this.uploadList)
        	this.uploadList = []
        	this.number = 0
        	this.$emit('input', this.listToString(this.fileList))
      	}
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值