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

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了前端获取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的返回值实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本宝典。

脚本宝典总结

以上是脚本宝典为你收集整理的前端获取http状态码400的返回值实例全部内容,希望文章能够帮你解决前端获取http状态码400的返回值实例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:http