代码:
<el-upload
ref="upload"
:auto-upload="false"
class="upload-demo"
action=""
multiple
:show-file-list="false"
:on-change="getFileName"
:before-upload="getFileName"
:on-success="sucCallBack"
:on-error="errCallBack">
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
<el-button style="margin-left: 10px;" size="small" type="primary">预览</el-button>
</el-upload>
methods:{
//上传前方法
getFileName(file){
this.changeForm.fileName = file.name;
this.formData = new FormData();
this.formData.append('files', file.raw); //file.row 重点
},
//上传方法
insertDataLoading(){
this.formData.append('workType', '变更'); //其余的参数
//this.formData中包含file.raw 与 所有需要的参数
this.api.upDataLoading(this.formData).then(response => {
console.log(response);
})
}
}