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.