前端取得http狀態碼400的返回值案例_基礎圖文說明教程
發表時間:2023-09-08 來源:明輝站整理相關軟件相關文章人氣:
[摘要]下面我就為大家帶來一篇前端獲取http狀態碼400的返回值實例。現在就分享給大家,也給大家做個參考。如下所示:axios.get("/check_mobile_and_sent_code",{withCredentials:true,params:{mobile:formInl...
下面我就為大家帶來一篇前端獲取http狀態碼400的返回值實例�,F在就分享給大家,也給大家做個參考。
如下所示:
axios.get("/check_mobile_and_sent_code",{withCredentials:true,params:{mobile:formInline.mobile}}).then(res=>{
console.log(res);
//if(res.result==true){
if (!this.timer) {
this.count = this.TIME_COUNT;
this.show = false;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= this.TIME_COUNT) {
this.count--;
} else {
this.show = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000)
}
//}
}).catch(error=>{
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
console.log('Error', error.message);
console.log(error.config);
})
使用場景:
當后端判斷驗證的手機號已存在的時候會返回400,這時需要跳到error條件中,得到后臺400的返回數據如上。
以下是error.response返回值:

這里如果直接輸出error,等于error.message
附狀態碼為200的返回值:

上面是我整理給大家的,希望今后會對大家有幫助。
相關文章:
JavaScript在IE9之前版本中內存泄露問題(詳細總結)
設計模式中的facade外觀模式在JavaScript開發中的運用(高級篇)
JavaScript設計模式開發中組合模式的使用教程(高級篇)
以上就是前端獲取http狀態碼400的返回值實例_基礎教程的詳細內容,更多請關注php中文網其它相關文章!
網站建設是一個廣義的術語,涵蓋了許多不同的技能和學科中所使用的生產和維護的網站。