使用formdata等格式传参调用服务一些写法
使用axios,set或者append都可以
let formData = new FormData()
formData.set('body', params[0])
formData.set('companyName', params[1]);
formData.set('payType', params[2]);
formData.set('orderNum', params[3]);
formData.set('total_fee', params[4]);
formData.set('token', params[5]);
axios({
method: 'post',
url: `${urlConfig.pcPay}`,
data: formData,
headers: {
'Content-Type':'multipart/form-data',//'application/json;charset=UTF-8'
'token': localStorage.getItem('token')
}
}).then(function (response) {
return response;
}
)
.catch(function (error) {
return error;
});
使用request
const reqParam ={
method:'post',
url:`${urlConfig.pcPay}`,
headers: {
'Accept':'application/json;charset=UTF-8',//深渊巨坑!
'token': localStorage.getItem('token')
},
body:formData,
};
return request(`${urlConfig.pcPay}`, reqParam);
来源:oschina
链接:https://my.oschina.net/u/3204029/blog/4713751