平时做技术实践时,很多问题不是概念不会,而是细节没串起来。拿“前端获取http状态码400的返回值实例”来说,它看着像小点,放到项目里常会牵出环境、配置、兼容性和维护成本。下面按实际采用顺序,把思路、关键写法和容易踩坑的地方讲清楚,便于大家直接对照操作。
如下所示所示:
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的得到值:

实际处理时,以上这篇前端拿到http状态码400的得到值实例就是分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多兼容脚本之家。
您可能感兴趣的文章:
- feign客户端HTTP状态码为204时 响应体被忽略的问题
- Laravel中正确地得到HTTP状态码方法示例
- 10个常用的HTTP状态码详解
- http 200、301、304等状态码详解
- Http状态码及含义详解