上传成功的 icon 有一个onSuccess() api
默认进度条有一个onProgress() api
this.$axios({
method: 'post',
url: this.upload.url,
data:formdata,
config,
onUploadProgress: progressEvent => {//axios自带api,获取上传进度
const complete = parseInt(
((progressEvent.loaded / progressEvent.total) * 100) | 0,
10
)
data.onProgress({ percent: complete })//调用组件自带进度条
}
}).then(res=>{
data.onSuccess()//显示完成按钮小图标
}).catch(err => {
if (err.response.status && err.response.status == 500){
this.$message.warning(err.response.data.msg)
}
let uid = data.file.uid
let idx = this.$refs.upload.uploadFiles.findIndex(item => item.uid === uid) // 关键作用代码,去除文件列表失败文件(uploadFiles为el-upload中的ref值)
this.$refs.upload.uploadFiles.splice(idx, 1) // 关键作用代码,去除文件列表失败文件
})
},