前端获取http状态码400的返回值实例

所属分类: 网络编程 / CSS/HTML 阅读数: 480
收藏 0 赞 0 分享

如下所示:

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的返回值实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

推荐深入理解css中的position定位和z-index属性

推荐深入理解css中的position定位和z-index属性
收藏 0 赞 0 分享

不错的10个你未必知道的CSS技巧

不错的10个你未必知道的CSS技巧
收藏 0 赞 0 分享

一点小小的创意css鼠标放上去则显示电话号码

一点小小的创意css鼠标放上去则显示电话号码
收藏 0 赞 0 分享

固定表格的高度超过指定高度就隐藏的方法

固定表格的高度超过指定高度就隐藏的方法
收藏 0 赞 0 分享

推荐个Css的filter常用滤波器属性及语句大全

推荐个Css的filter常用滤波器属性及语句大全
收藏 0 赞 0 分享

淘宝段正淳的css笔记大全第1/4页

淘宝段正淳的css笔记大全
收藏 0 赞 0 分享

CSS实现的一个图片放大展示的一种思路

CSS实现的一个图片放大展示的一种思路
收藏 0 赞 0 分享

用css滤镜实现的文字描边效果的代码

用css滤镜实现的文字描边效果的代码
收藏 0 赞 0 分享

用css实现的带阴影的表格效果的代码

用css实现的带阴影的表格效果的代码
收藏 0 赞 0 分享

又一实用的常用CSS缩写语法收集

又一实用的常用CSS缩写语法收集
收藏 0 赞 0 分享
查看更多