浏览代码

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
 })