vue 接口监听 实现 跳转login

接口监听 跳转login

import http from './modules/api/http';
Vue.prototype.$axios = http;
Vue.http.interceptors.push((request, next) => {
    if (request.method === 'GET') {
        request.headers.map["If-Modified-Since"] = ["0"];  //IEget缓存解决
    }
    clearTimeout(loadingTimer);
    loadingTimer = setTimeout(() => {
        vm.$Loading.start();
    }, 300);

    next((response) => {
        if (loadingTimer) {
            clearTimeout(loadingTimer);
            loadingTimer = null;
        }
        vm.$Loading.finish();
        if (response.status === 401) {
            router.push('/login');                  //没有权限弹出去
        }
        if (String(response.status)[0] === '5') {//非本地测试关闭
            // if( /(127.0.0.1)/.test(window.location.href) ){
            //     alert('服务器内部错误');   //服务器内部错误
            // };
        }
    });
}

你可能感兴趣的:(vue.jsaxios)