Aioxs拦截器配置

axios.interceptors.request.use(
   
   config => {
     if(store.state.token){
         config.headers.Authorization = `token ${store.state.token}`;
       }  
       return config;

  },
err =>{
   return Promise.reject(err);
 });

axios.interceptors.response.use(
   response => {
     return response;
  },
  error =>{
    if(error.response){
     switch (error.response.status){
         case 401:
                 store.commit(types:LOGOUT);
                  router.replace({
                     path:'login',
                     query:{redirect:router.currentRoute.fullPath}
                  })
       }

     }
     return Promise.reject(error.response.data)
   });

 

posted @ 2020-10-14 19:53  cruor  阅读(166)  评论(0编辑  收藏  举报