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.

posted on 2021-09-23 11:42  微笑点燃希望  阅读(1618)  评论(0编辑  收藏  举报
font=white