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.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM