问题
- 后端已经配置了跨域没有问题
- 发送get请求没有出现跨域的错误,发送post的请求就出现的跨域的错误,这到底是为什么呢?
解决
axios.post(BASEURL+'/api/devices/activate ',{}).then((res)=>{
console.log(res);
}).catch((res)=>{
})
axios.post(BASEURL+'/api/devices/activate ',JSON.stringify({})).then((res)=>{
console.log(res);
}).catch((res)=>{
})
小插曲
- 这样传输可能会导致后端获取不到数据
- 终极解决方案
加上这个header头就是可以解决
axios.post(BASEURL+'/api/activate ',{
device_code:DEVICECODE,
code:'dasasdf'
},{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then((res)=>{
console.log(res);
}).catch((res)=>{
})