1.问题:
【1】formData为空:
let fileFormData = new FormData();
fileFormData.append('file', This.fileList[0].raw);
console.log(fileFormData)//为空,其实是有数据的
改为:
console.log(fileFormData.get('file'))
【2】报500错:
这个是由于接口封装造成的
2.解决:
// 文件上传
submitUpload() {
const This = this;
let fileFormData = new FormData();
fileFormData.append('file', This.fileList[0].raw);
fileFormData.append('stationId', This.queryParam.stationId);
// consigneeImport(fileFormData).then((res) => {
// if (res.data.code == 0) {
// This.$message.success('文件导入成功');
// This.fileList = [];
// This.getconsigneeList();
// }
// });
this.$axios({
url: this.apiUrl + '/api/import',//this.apiUrl是main.js里面的,如下图
method: 'POST',
data: fileFormData,
headers: {
'Token': This.user.token,//存储的token
'Content-Type': 'multipart/form-data',
}
}).then(res => {
if (res.data.code == 0) {
this.$message.success(res.data.msg);
This.fileList = [];
This.getconsigneeList();
} else {
this.$message.error(res.data.msg)
}
})
},


版权声明:本文为weixin_53791978原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。