首页 > 其他分享 >element-ui upload自定义formdata上传文件和参数

element-ui upload自定义formdata上传文件和参数

时间:2022-12-10 14:23:41浏览次数:51  
标签:自定义 form formdata upload fileList invCode let file msg

  <el-upload list-type="text" action="" :http-request="HandleHttpRequestDescFile" :on-remove="handleRemoveDescFile" :file-list="this.fileList" ref="upload">             <el-button size="small" type="primary" title="需求附件">点击上传PBC文件</el-button> </el-upload>   //上传     HandleHttpRequestDescFile(a){       let fileName = a.file.name;       let pos = fileName.lastIndexOf(".");       let lastName = fileName.substring(pos, fileName.length);       if (lastName.toLowerCase() !== ".xlsx") {         this.msgError("文件必须为.xlsx类型")         this.fileList = []         this.form.file = null       } else {         this.fileList = []         this.form.file = a.file         this.fileList.push(a.file)       }     },   //删除方法     handleRemoveDescFile(file) {       this.fileList = []       this.form.file = null       // if(this.descFile != ''){       //   this.descFile.pop(file);       // }     },   /** 提交按钮 */     submitForm() {       console.log(this.fileList)       let msg = ''       if(this.form.file == null){         msg = '请上传PCB文件!'       }       if( this.form.invCode == ''|| this.form.invCode == undefined || this.form.invCode == null){         msg = '物料编码不能为空!'       }       if (msg != '') {         this.msgError(msg)             return       }       var formData = new FormData();       formData.append('files',this.form.file);       formData.append('invCode',this.form.invCode);       uploadFile(formData).then(res=>{         if(res.code == 200){           this.msgSuccess("成功");           this.open = false;           this.getList();         }else{           this.$message({ type: 'error', message: res.errmsg });         }       });     },       //上传 export function uploadFile(data) {     let config = {       headers: {         "Content-Type": "multipart/form-data"       }     }     return request({       url: '/api/smt/record/inv/files',       method: 'POST',       data: data,       headers: config,     })   }

标签:自定义,form,formdata,upload,fileList,invCode,let,file,msg
From: https://www.cnblogs.com/cw828/p/16971519.html

相关文章