出错原因 :
后台接收不到参数问题,查看请求参数格式还是json的数据格式
一、axios里面添加 config.data = $.param(config.data)
axios.defaults.headers['mytoken'] = 'aaa'
axios.interceptors.request.use(function (config) {
config.headers.mytoken = '11111';
config.data = $.param(config.data);
return config;
}, function (err) {
console.log(err)
})
axios.post('http://localhost:3000/axios', {
uname: 'kepeng',
pwd: 111111
}).then(ret => {
console.log(ret)
})
二、修改post请求参数为params格式
axios.defaults.headers['mytoken'] = 'aaa'
axios.interceptors.request.use(function (config) {
config.headers.mytoken = '11111';
return config;
}, function (err) {
console.log(err)
})
const params = new URLSearchParams()
params.append('uname','kepeng')
params.append('pwd','123456')
axios.post('http://localhost:3000/axios',params).then( ret=> {
console.log(ret.data)
})