Browse Source

解决登录接口会传token的bug

hzj18279462576@163.com 1 tuần trước cách đây
mục cha
commit
92f40b4fa7
3 tập tin đã thay đổi với 17 bổ sung4 xóa
  1. 1 1
      src/router/index.js
  2. 14 2
      src/utils/request.js
  3. 2 1
      vite.config.js

+ 1 - 1
src/router/index.js

@@ -79,7 +79,7 @@ const routes = [
   // },
   // },
 ];
 ];
 const router = createRouter({
 const router = createRouter({
-  history: createWebHashHistory("/alumnus/welcomeWeb"),
+  history: createWebHashHistory("/welcome/welcomeWeb/"),
   routes,
   routes,
 });
 });
 
 

+ 14 - 2
src/utils/request.js

@@ -9,8 +9,20 @@ const instance = axios.create({
 // 请求拦截器
 // 请求拦截器
 instance.interceptors.request.use(
 instance.interceptors.request.use(
   (config) => {
   (config) => {
-    // 添加 token 等通用处理
-    // config.headers["Content-Type"] = "application/json;charset=utf-8";
+    // ========== 新增:判断登录接口,登录接口不携带token ==========
+    const loginApiList = [
+      '/welcome/api/home/login'  // 你的登录接口完整路径,按你项目实际改
+      // '/welcome/welcome_api/register' // 注册如果也不需要token一并加上
+    ];
+    // 判断当前请求地址是否包含登录接口
+    const isLoginApi = loginApiList.some(api => config.url.includes(api));
+
+    // 如果是登录接口,直接放行,不处理token逻辑
+    if (isLoginApi) {
+      return config;
+    }
+
+    // 非登录接口才执行token逻辑
     const token = localStorage.getItem("token");
     const token = localStorage.getItem("token");
     const userhead = localStorage.getItem("userhead");
     const userhead = localStorage.getItem("userhead");
     if (token) {
     if (token) {

+ 2 - 1
vite.config.js

@@ -48,7 +48,8 @@ export default defineConfig({
     // },
     // },
   },
   },
   publicDir: "public",
   publicDir: "public",
-  base: "./",
+  // base: "/",
+  base:"/welcome/welcomeWeb/",
   // 打包配置
   // 打包配置
   build: {
   build: {
     target: "modules", //设置最终构建的浏览器兼容目标  //es2015(编译成es5) | modules
     target: "modules", //设置最终构建的浏览器兼容目标  //es2015(编译成es5) | modules