<el-upload
ref="upload"
action
multiple
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:http-request="uploadFiles"
>
<i class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="" />
</el-dialog>
handleRemove(file, fileList) {
console.log(file, fileList);
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url;
this.dialogVisible = true;
},
uploadFiles(files) {
const _file = files.file;
var formData = new FormData();
formData.append("files", _file);
formData.append("args", "cmdb");
upload(formData)
.then((res) => {
if (res.code == 0) {
this.$message.success("上传成功");
} else {
res.desc && this.$message.error(res.desc);
}
})
.catch((err) => {
err.desc && this.$message.error(err.desc);
});
},