elementui el-upload實現(xiàn)不自動上傳,將上傳內(nèi)容放在formData里面,傳遞給后端
//這種情況一般是要彈出一個彈框進行上傳操作
<el-upload ref="upload" action="" name="fileList" :show-file-list="false" :auto-upload="false" :multiple="true" :headers="header" :on-change="onSuccess" :on-error="onError" > <el-button slot="trigger" size="small" type="primary">選取文件</el-button> </el-upload>
methods:{ onSuccess(response) { this.filesList.push(response); },
onError(err) {
var errData = JSON.parse(err.message);
this.$notify({
title: "警告",
message: errData.message,
type: "warning",
});
},
// 彈框確定按鈕 handlerOk(){ let formData = new FormData();
formData.append('newAgent', this.addParams.newAgent); formData.append('hostsList', this.addParams.hostsList); //將上傳列表循環(huán)添加到表單里面 this.filesList.forEach(ele=>{ formData.append('filesList', ele.raw); }) const loading = this.$loading({ lock: true, text: 'Loading', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }); this.$axios .post("/api/...........", formData) .then((res) => { if (res.data.code == 200) { this.$message.success("操作成功"); loading.close(); } }); }, }

浙公網(wǎng)安備 33010602011771號