<el-form-item label="上传文件" v-if="!mask">
<el-upload ref="upload" action="" class="upload-demo" :http-request="httpRequest" :multiple="false" :limit="1" :auto-upload="false" accept=".yaml">
<el-button size="small" type="primary">选择文件</el-button>
<div slot="tip" class="el-upload__tip">只能上传yaml文件</div>
</el-upload>
</el-form-item>
httpRequest(param) {
if(param){
this.form.file = param.file;
}
},
获取上传文件
提交事件
submitForm(){
this.$refs.upload.submit()
// 新建form表单
let formData = new FormData();
if(this.form.file != ""){
formData.append("file", this.form.file);
}
//把FormData传向后端
addFun(FormData).then((res)=>{
...
})
}
export function addList(data) {
return request({
method: 'POST',
url: '/',
data: data,
contentType: false,
headers: {
"Content-Type": "multipart/form-data",
},
})
}
//清空表单
reset() {
this.form = {
id: undefined,
name: "",
level: "",
cveid: "",
description: "",
descriptionChinese: "",
file:"",
nameChinese:"",
solution:""
};
this.resetForm("form");
},
//this.$refs.upload.clearFiles() 清空上传的文件