|
@@ -1,4 +1,6 @@
|
|
|
import axios from 'axios';
|
|
|
+import Vue from 'vue'
|
|
|
+import router from '@/router/index'
|
|
|
axios.defaults.timeout = 5000;
|
|
|
axios.defaults.baseURL ='';
|
|
|
|
|
@@ -31,16 +33,23 @@ axios.interceptors.request.use(
|
|
|
//http response 拦截器
|
|
|
axios.interceptors.response.use(
|
|
|
response => {
|
|
|
- if(response.data.errCode ==2){
|
|
|
+ if (response.data.errCode == 2) {
|
|
|
router.push({
|
|
|
- path:"/login",
|
|
|
- querry:{redirect:router.currentRoute.fullPath}//从哪个页面跳转
|
|
|
+ path: "/login",
|
|
|
+ querry: { redirect: router.currentRoute.fullPath }//从哪个页面跳转
|
|
|
})
|
|
|
}
|
|
|
return response;
|
|
|
},
|
|
|
error => {
|
|
|
- return Promise.reject(error)
|
|
|
+ if (401 === error.response.status) {
|
|
|
+ localStorage.clear();
|
|
|
+ console.log(window.location);
|
|
|
+ window.location.href = window.location.origin;
|
|
|
+ alert("登录状态已过期!请重新登录!");
|
|
|
+ } else {
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
}
|
|
|
)
|
|
|
|