Browse Source

feat: axios未登录跳转登录拦截器逻辑实现

cuiyalong 3 years ago
parent
commit
8ab4fb92d2
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/api/axios.js

+ 8 - 0
src/api/axios.js

@@ -17,6 +17,14 @@ service.interceptors.request.use(config => {
 
 // 添加一个返回拦截器
 service.interceptors.response.use(response => {
+  // 此处添加响应拦截
+  if (process.env.NODE_ENV === 'production') {
+    const noPermissionText = ['未登录', '需要登录']
+    const noPermission = noPermissionText.includes(response.data.error_msg)
+    if (noPermission) {
+      location.href = '/notin/page'
+    }
+  }
   return response.data
 })