最后需要隐藏添加后的文件 方法:
第一步:
<el-form-item style="float:right;">
<el-upload
class="upload-demo"
action
multiple
:http-request="upload"
:file-list="fileList"
:on-success="onSuccess"
:on-error="onError"
>
<el-button size="small" type="success" :loading="importLoading">批量导入</el-button>
</el-upload>
</el-form-item>
第二步:
// 上传文件时的回调
upload(fileObj) {
this.importLoading = true
let formData = new FormData();
formData.append("file", fileObj.file);
formData.append("proCateCode", "0a2313388d4347d6b683d40ce609a4c2");
Common.post(
`/carpermission/cpProductCar/saveMulCarGuDing`,
formData
).then(res => {
this.importLoading = false
if (res.code === 200) {
console.log(res.date,1111111)
fileObj.onSuccess(res.data)
} else {
fileObj.onError('失败', err)
}
}).catch(err => {
this.importLoading = false
fileObj.onError('失败', err)
})
},
// 文件上传成功的回调
onSuccess(response, file, fileList) {
// console.log(response,'response');
let error = response.log.length === 0?"无":response.log.join(";</br></br>")
console.log(error)
if(response.noImportCarNo.length === 0){
this.$message({
dangerouslyUseHTMLString: true,
showClose: true,
duration: 5000,
type: 'success',
message: '<strong>操作完成!'+'</strong>'
});
}else{
this.$message({
dangerouslyUseHTMLString: true,
showClose: true,
duration: 5000,
type: 'success',
message: '<strong>操作完成!</br></br>'
+
'未导入车牌:' + response.noImportCarNo.join(",") + '</br></br>'
// +
// '已导入车牌:' + response.importCarNo.join(",") + '</br></br>'
+
error
+
'</strong>'
});
}
this.getEffectivePro() //上传文件成功后重新刷新列表
// console.log(response, file, fileList)
},
// 文件上传失败的回调
onError(err, file, fileList) {
this.$message({
message: '导入失败!',
type: 'error'
});
},
},
};
第三步:
.fixed-car ::v-deep .el-upload-list {
display: none;
}