axios拦截器,统一加headers,请求接口

   // 获取路由的地址
    let pathname = location.pathname;
    if(localStorage.getItem('token')){
        if(pathname != '/' &&  pathname != '/login' &&  pathname != ' ' ){
            config.headers.common['token'] = localStorage.getItem('token');
            console.log('kk');

        }else {
            // 不是登陆页面就将 header 为 null
            config.headers.common= null ;
        }
    }

你可能感兴趣的:(axios拦截器,统一加headers,请求接口)