参考:
https://segmentfault.com/a/1190000021388082
https://blog.csdn.net/qq_34867424/article/details/102719581
配置axios拦截器:
const request = axios.create({ baseURL: process.env.VUE_APP_BASE_ZYAPI, timeout: 5000 // 请求超时 }) // 拦截token过期的情况 request.interceptors.response.use( function(response) { return response }, function(error) { if (error.response) { switch (error.response.status) { case 401: Message.warning("登录信息已过期,请您重新登录!") store.dispatch(‘user/logout‘); router.replace({ path: ‘/login‘, }); break; } } else { // 没有返回 store.dispatch(‘user/logout‘); router.replace({ path: ‘/login‘, }); } return Promise.reject(error); } )