示例代码
<div class="item" v-for="(item,index) in lbtList"><!-- 图片上传 --><div><el-uploadaction="#":ref="'upload'+index"list-type="picture-card":limit="1":file-list="item.fileList":http-request="handleFileUpload":on-preview="handlePictureCardPreview":on-change="file=>{handleChange(file,item.fileList,index)}":on-remove="file=>{handleRemove(file,item.fileList,index)}":auto-upload="false"accept=".jpg, .jpeg, .png":class="{ hide: item.hideUpload}"><div class="upload-inner"><imgsrc="../../assets/image/shangchuan.png"alt=""/><div id="upload-text1">点击上传</div><div id="upload-text2">支持JPG、PNG等格式</div></div></el-upload></div>
</div>
触发方法:
lbtFn(){
for(var i=0;i<this.lbtList.length;i++){
this.$refs['upload' + i][0].submit()
}
},
之所以一直报错的原因是我之前写的触发方法是 this.$refs['upload' + i].submit()导致一直undefied,说没有这个方法,后面才发现是获取的方式不对,而应该是this.$refs['upload' + i][0].submit()。