在项目中,上传文件时接口不想使用action,可以用到这个属性
<a-upload
name="file"
:multiple="true"
:headers="headers"
:showUploadList="false"
:beforeUpload="handleBeforeUpload"
:customRequest="customRequest" >
<a-button type="primary" class="btnClass" style="margin: 0 10px;">导入</a-button>
</a-upload>
调用接口时这样写
// 自定义上传,自定义上传接口
customRequest(file) {
// file 是上传的文件
// 后端需要接受的参数是 formData数据,
const form = new FormData();
form.append('file', file.file);
//这里的this.year是项目中需要传的参数
uploadFile(this.year, form).then(res => {
if(res) {
this