ruoyi-vue-pro[芋道yudao]登录失败问题分析

ruoyi-vue-pro只能在我电脑上登录,换台电脑登录就报错

先按F12查看控制台报错原因

service.ts:182 errAxiosError: Network Error
warn$1 @ runtime-core.esm-bundler.js:51
logError @ runtime-core.esm-bundler.js:263
handleError @ runtime-core.esm-bundler.js:255
(匿名) @ runtime-core.esm-bundler.js:209
Promise.catch
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:208
emit @ runtime-core.esm-bundler.js:6349
(匿名) @ runtime-core.esm-bundler.js:8062
handleClick @ use-button.ts:61
callWithErrorHandling @ runtime-core.esm-bundler.js:199
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:206
invoker @ runtime-dom.esm-bundler.js:722
index.ts:9 
            
            POST http://localhost:48080/admin-api/system/auth/login net::ERR_CONNECTION_REFUSED
dispatchXhrRequest @ xhr.js:195

这里有一个关键信息就是POST http://localhost:48080/admin-api/system/auth/login net::ERR_CONNECTION_REFUSED
地址请求的是localhost,这也就说明了为什么只能我登录上去,知道原因就好办了。
找到.env后缀文件,查看定义的路径

env文件

这里定义的是localhost,因为我这个项目后期肯定是前后端部署在同一台服务器上,所以我直接动态获取IP,找到src\config\axios\config.ts

 /**
   * api请求基础路径
   */
  // base_url: import.meta.env.VITE_BASE_URL。改为动态获取
   base_url: window.location.protocol + "//" + window.location.hostname + ":48080" + import.meta.env.VITE_API_URL,

重启项目OVER
重新在另一台设备上打开项目,搞定

posted @ 2025-02-14 16:30  四季山川  阅读(880)  评论(0)    收藏  举报