相关疑难解决方法(0)

axios库中的超时功能无效

我已经设定 axios.defaults.timeout = 1000;

我停止了为我提供API的服务器.

但发送请求后超时需要1秒以上.

这是我的请求的样子:

import axios from 'axios';
axios.defaults.timeout = 1000;

return axios.post(`${ROOT_URL}/login/${role}`, creds).then((response) => {
      console.log(response);

        if(response.status === 200) {
          // If login was successful, set the token in local storage
          localStorage.setItem(`${role}_log_toks`, JSON.stringify(response.data));

          // Dispatch the success action
          dispatch(receiveLogin(response.data));

          return response;
        }
      }).catch(err => {
        console.log(err);
        // If there was a problem, we want to
        // dispatch the error condition
        if(err.data && err.status === 404) {
          dispatch(loginError(err.data));
        } else {
          dispatch(loginError('Please check your network connection and …
Run Code Online (Sandbox Code Playgroud)

javascript ajax xmlhttprequest redux axios

20
推荐指数
5
解决办法
3万
查看次数

标签 统计

ajax ×1

axios ×1

javascript ×1

redux ×1

xmlhttprequest ×1