上传文件使用FormData对象发送
let formData = new FormData();
formData.append('file', this.addItem.file);
这里还有一点就是不要忘记改变请求头
headers: {
'Content-Type': 'multipart/form-data'
}
下面是一个上传文件代码
let formData = new FormData();
formData.append('albumIds', this.addItem.type);
formData.append('albumType', this.addItem.type);
formData.append('file', this.addItem.file);
formData.append('jobName', this.addItem.name);
formData.append('judgedType', this.addItem.judgedType);
formData.append('subType', this.addItem.subType);
let config = {
headers: {
'Content-Type': 'multipart/form-data'
}
}
axios.post(baseUrl+'/judge/multiPerson/add',param,config)
.then(function(response) {
if (callback) {
callback(response);
}
obj.$Loading.finish();
})
.catch(function(err) {
obj.$Message.error({
content: '多人检索新增出错!' + err,
duration: 5
});
obj.$Loading.error();
});