二次封装的axios进行了全局的设置
//设置请求头
axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'
//设置传递数据的格式
axios.defaults.transformRequest = data => qs.stringify(data);
但是在图片上传功能时,需要改变全局的默认设置,代码如下:
//上传文件的doupfile方法
function doupfile(data, config) {
return axios.post("/manager/sys/upfile/doupfile.action", data, config);
}
this.$api.pub
.doupfile(formData, {
// 修改请求头
headers: { "Content-Type": "multipart/form-data" },
transformRequest: function (data) {
// 对 data 进行处理
return data
},
})
.then(function(res) {
console.log(res);
});