axios多文件上传,文件上传取消某一个文件上传
//点击上传后
upload() {
file.files.forEach((val, index) => {
var formda = new FormData();
formda.append("multipartFile", file.files[index]);
console.log(formda.get("multipartFile"));
// 创建token用于取消上传
var ss = axios.CancelToken.source();
this.source.push(ss);
request({
url: "/uploadMinio",
method: "post",
data: formda,
headers: {
"content-type": "multipart/form-data",
},
//原生获取上传进度的事件
onUploadProgress: function (progressEvent) {
console.log(progressEvent);
let complete =
((progressEvent.loaded / progressEvent.total) * 100) | 0;
if(complete == 100){
complete == 99
}
that.tableData[index].address = complete;
},
// 取消上传方法
cancelToken: ss.token,
})
.then((res) => {
console.log(res);
that.tableData[index].fileLoadedName = res.fileSavedName;
that.tableData[index].address = 100;
})
.catch((err) => {
console.log(err);
});
});
},
每次都把文件的token保存在data中
//取消按钮 <template slot-scope="scope"> <div class="delData" @click="delfile(scope.$index)">取消</div> </template> //取消上传 delfile(idx) { this.source[idx].cancel('取消上传'); },

浙公网安备 33010602011771号