vue this.$http.get post 跨域问题

Get请求:

Vue.http.get('http://localhost:9090/card-add',{
params:{id:1,name:'aaa'}....->get请求必须加params
})
.then(
(response)=>{
//-响应成功回调
console.log(response.data)
},
(response)=>{
//-响应错误回调
});
浏览器正确情况:

this.$http.get(this.url.getInfoURL?idNumber:idnumber,{
emulateJSON: true
}).then(res => {
console.log("res={}",res);
if (res.code === 0) {
let dataObj = res.data;

this.swCode = dataObj.swCode;

this.regName = dataObj.regName;
} else {
this.descText = '获取失败,请稍后重试'
}
}).catch(err => {
return this.$api.msg("服务器被外星人抓走了,请稍后重试")
});

Post请求:

Vue.http.post('http://localhost:9090/st-add',{
stName:"jxh",//st.stName,
idCard:st.idCard,
sex:st.sex,
school:st.school,
depict:st.depict,
birthday:'2019/11/11',//st.birthday,
clubs:st.clubs
},{
emulateJSON: true -->这一段必须存在!
})
.then(
(response)=>{
//-响应成功回调
console.log(response.data)
},
(response)=>{
//-响应错误回调
});

post错误情况,浏览器状况:

这种错误情况,请和上面比对,你虽然能看到全部的请求参数,但结果就是404.

原文地址:https://www.cnblogs.com/lykbk/p/dsfdsfdffer5ret454545.html