添加 :http-request="selfUpload"
:
<el-upload:disabled="saveLoading"class="upload-demo":limit="1":on-exceed="handleExceed":before-upload="beforeAvatarUpload":file-list="fileList":auto-upload="true":http-request="selfUpload"accept=".xls,.xlsx"><el-button size="small" type="primary">上传excel</el-button>
</el-upload>
编写自定义上传方法handleExceed()
,在方法里面调用uploadFile()
发送上传请求:
selfUpload(params) {const formData = new FormData(); formData.append('file', params.file); // 上传文件formData.append('wechat', 86654698); // 上传参数formData.append('headers', getStore('Access-Token')) // 上传其他参数this.uploadFile(formData) // 发送请求},
uploadFile(params) {this.saveLoading = truepost('/upload/file',params).then(res=>{if(res.data.code===200){this.$message.success(res.data.msg)}else {this.$message.error(res.data.msg)}this.saveLoading = falsethis.fileList = [] // 清空上传列表}).catch((err) => {this.saveLoading = falseconsole.log(err)})},