vue里axios post请求传参接收不到问题
axios 格式默认为payload,而我们常用为form-data,所以只需要转换一下就好,话不多说,上代码
axios.create.interceptors.request.use(
config => {
if (store.getters.token) {
config.headers['token'] = getToken()
}
if (config.data) {
config.data = qs.stringify(config.data)
}
config.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
config.responseType = 'json'
return config
},
error => {
// do something with request error
console.log(error) // for debug
return Promise.reject(error)
}
)