
<el-upload action="/api/uploads" :file-list="addForm.files" list-type="picture-card" :on-preview="handlePictureCardPreview" :on-remove="handleRemove" :limit="8" :before-upload="beforeUpload" :on-success="uploadSuccess"><i class="el-icon-plus"></i>
</el-upload>
file-list是数组的形式
export default{
data(){
addForm:{
files:[{name:'xxx.jpg',url:'xxx.jpg'},{name:'xxx2.jpg',url:'xxx.2jpg'}]
}
}
}
上传成功方法,采用数组合并的思路
uploadSuccess(response, file, fileList){
let files = {name:response,url:response};
this.addForm.files.push(files);
}
删除图片的方法
handleRemove:function(file, fileList) {
for (var i in this.addForm.files) {
for (var k in this.addForm.files[i]) {
if (this.addForm.files[i][k] == file.uid) {
delete this.addForm.files[i];
break;
}
}
}
},

本文介绍如何使用Element UI中的文件上传组件实现图片上传功能,包括上传成功后的处理及删除图片的方法。通过数组合并的方式更新文件列表,并展示了具体的数据结构和方法实现。
1039

被折叠的 条评论
为什么被折叠?



