axios post传参后台无法接收问题

起因是在angular项目中使用axios发送post请求,向后台传参后台一直无法接收,网上查了有说是请求头设置不对,需要把Content-Type:application/x-www-form-urlencoded;charset=UTF-8

改了之后发现还是不行,后来终于找到原因,axios请求中params和data,不一样,post需要把参数放在data中,get请求放在params中才行

//POST请求
sendIndentifyCodeServer(opt){ axios.post(`${environment.path}
/IdentifyingCode/getVcode`,opt.data).then((response)=>{ if(opt.onSuccess){ opt.onSuccess(response); } }).catch(error=>{ if(opt.onFailed){ opt.onFailed(error); } }); }


//GET请求
sendIndentifyCodeServer(opt){ axios.get(`${environment.path}/IdentifyingCode/getVcode`,{params:opt.data}).then((response)=>{ if(opt.onSuccess){ opt.onSuccess(response); } }).catch(error=>{ if(opt.onFailed){ opt.onFailed(error); } }); }
原文地址:https://www.cnblogs.com/leiting/p/8475552.html