• 现象:
    在这里插入图片描述
  • 解决
    出现该错误的原因是:发送请求后实际时间超出了设定时间或者默认时间,有可能是网络情况不好、或者服务端挂掉了等原因有关,可以延长请求超时的时间。

1.axios请求超时,返回的error是一个对象,用typeof检测是object,error对象的具体内容如下图:
2.如何得到 timeout of …,用返回的对象调用message即可,例如error.message
3.axios.defaults.timeout = 50; // 超时时间(在拦截器中统一设置超时时间)
4.具体如何设置请求时间点击此处
在这里插入图片描述
其他时候的错误处理:

 .catch(function (error) {
    if (error.response) {
      // 请求已发出,但服务器响应的状态码不在 2xx 范围内
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
    } else {
      // Something happened in setting up the request that triggered an Error
      console.log('Error', error.message);
    }
    console.log(error.config);
  });
Logo

前往低代码交流专区

更多推荐