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