소스 검색

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

cuiyalong 3 년 전
부모
커밋
8ab4fb92d2
1개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  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
 })