zoukankan      html  css  js  c++  java
  • vue 设置请求超时时间处理

    Vue.http.post('http://114.214.164.77:2222/crptorgraphy',{msg:JSON.stringify(req)},{emulateJSON:true,_timeout:3000,
               onTimeout: (request) => {
                   //超出时间你要处理的逻辑
                    
               }}).then((response) => {
        }, (error) => {
            
        });
    //拦截器设置全局请求token
    Vue.http.interceptors.push((request, next) => {
            //设置请求时间
            let timeout;
            // 如果某个请求设置了_timeout,那么超过该时间,会终端该(abort)请求,并执行请求设置的钩子函数onTimeout方法,不会执行then方法。
            if (request._timeout) {
                timeout = setTimeout(() => {
                    if(request.onTimeout) {
                        request.onTimeout(request);
                        request.abort()
                    }  
                }, request._timeout);
            }
            next((response) => {
                clearTimeout(timeout);
                return response
            })
    })
  • 相关阅读:
    软件开发术语
    网络规划与设计
    MPLS LDP协议
    MPLS 基础
    CallAfter
    LongRunningTasks
    Non-blocking GUI
    WorkingWithThreads
    Python: Running Ping, Traceroute and More
    wxPython and Threads
  • 原文地址:https://www.cnblogs.com/lizhao123/p/10983081.html
Copyright © 2011-2022 走看看