//在main.js设置全局的请求次数,请求的间隙
axios.defaults.retry = 4;
axios.defaults.retryDelay = 1000; axios.interceptors.response.use(undefined, function axiosRetryInterceptor(err) {
var config = err.config;
// If config does not exist or the retry option is not set, reject
if(!config || !config.retry) return Promise.reject(err); // Set the variable for keeping track of the retry count
config.__retryCount = config.__retryCount || 0; // Check if we've maxed out the total number of retries
if(config.__retryCount >= config.retry) {
// Reject with the error
return Promise.reject(err);
} // Increase the retry count
config.__retryCount += 1; // Create new promise to handle exponential backoff
var backoff = new Promise(function(resolve) {
setTimeout(function() {
resolve();
}, config.retryDelay || 1);
}); // Return the promise in which recalls axios to retry the request
return backoff.then(function() {
return axios(config);
});
});

  参考地址:https://github.com/axios/axios/issues/164#issuecomment-327837467

vue axios请求超时,设置重新请求的完美解决方法的更多相关文章

  1. [转]axios请求超时,设置重新请求的完美解决方法

    自从使用Vue2之后,就使用官方推荐的axios的插件来调用API,在使用过程中,如果服务器或者网络不稳定掉包了, 你们该如何处理呢? 下面我给你们分享一下我的经历. 具体原因 最近公司在做一个项目, ...

  2. html 中设置span的width完美解决方法

    在默认情况下,由于span是行标签,设置width是无效的.只有改变display的属性,才可以实现设置宽度. 1.初步想法 span{ background-color:#ccc; display: ...

  3. Laravel dingo,HTTP的请求头(accept)无法携带版本号的解决方法

    Laravel dingo,HTTP的请求头(accept)无法携带版本号的解决方法  2017年9月6日  原创分享  zencodex  使用 Laravel dingo 做api开发时,涉及 A ...

  4. ios/iphone手机请求微信用户头像错位BUG及解决方法

    转:http://www.jslover.com/code/527.html ios/iphone手机请求微信用户头像错位BUG及解决方法 发布时间:2014-12-01 16:37:01 评论数:0 ...

  5. 设置height:100%无效的解决方法

    设置height:100%无效的解决方法 刚接触网页排版的新手,常出现这种情况:设置table和div的高height="100%"无效,使用CSS来设置height:" ...

  6. 误把Linux运行级别设置为6后的解决方法【转】

    本文转载自:http://www.wuji8.com/meta/841011126.html 误把Linux运行级别设置为6后的解决方法     我们知道,Linux有7个运行级别,而运行级别设置为6 ...

  7. Django与Vue语法冲突问题完美解决方法

    当我们在django web框架中,使用vue的时候,会遇到语法冲突. 因为vue使用{{}},而django也使用{{}},因此会冲突. 解决办法1: 在django1.5以后,加入了标签: {% ...

  8. UEditor设置内容setContent()失效的解决方法

    ueditor常见用法: https://blog.csdn.net/qq_31879707/article/details/54894735#UE.Editor:setContent() UEdit ...

  9. 精讲响应式WebClient第5篇-请求超时设置与异常处理

    本文是精讲响应式WebClient第5篇,前篇的blog访问地址如下: 精讲响应式webclient第1篇-响应式非阻塞IO与基础用法 精讲响应式WebClient第2篇-GET请求阻塞与非阻塞调用方 ...

随机推荐

  1. springboot根据yml配置文件选择性加载bean

    @Slf4j @Aspect @Component @ConditionalOnProperty(value = "localCache.apiCache", havingValu ...

  2. JavaScript编程艺术-第7章代码汇总(2)

    [7.4节] 重回“JavaScript美术馆”代码 ***亲测可用*** HTML: JS:

  3. Windows平台下Oracle 11g R2监听文件日志过大,造成客户端无法连接的问题处理

    近期部署在生产环境的应用突然无法访问,查看应用日志发现无法获取数据库连接. SystemErr R Caused by: oracle.net.ns.NetException: The Network ...

  4. 每天学点Linux命令: 管道| 与 xargs的区别

    先看一个例子: find ./ -print | xargs grep a 输出: grep: ./: 是一个目录 ./less:abc ./afile:abcde ./afile:AaAbBcB . ...

  5. connection failed to http://nssa-sensor3:11000/oozie/?user.name=oozie(<urlopen erroer Errno 111] Connection refused>)解决办法(图文详解)

    不多说,直接上干货! 解决办法 Copy/Paste oozie.services property tag set from oozie-default.xml to oozie-site.xml. ...

  6. TypeError: string indices must be integers, not str

    1. TypeError: string indices must be integers, not str 字符串类型取第index个字符的时候,应该传入int而不是str.如 1 a='abcde ...

  7. Django--2、form表单

    django中定义form表单的优势 HTML中提交后,若数据出现错误,返回的页面中仍然可以保留之前输入的数据. 通过校验规则可以方便的限制字段条件并校验. 在Django中建个form表单 先要确定 ...

  8. 动态排序JavaBean

    Java中如果对对象排序可以考虑实现Comparable接口,但是需要排序的属性一旦指定就不能再修改.BeanUtils组件提供了对JavaBean动态排序的支持,即可以在运行时指定排序的属性.实例运 ...

  9. ListView用法

    public class MainActivity extends Activity implements OnItemClickListener, OnScrollListener { privat ...

  10. [Windows Server 2012] 更改服务器密码

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★[护卫神·V课堂]是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:更改服务器 ...