Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
mlaj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-05-08 17:46:10 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
80b46d63eb834ad2d8802f7656ed5848f65d5d48
80b46d63
1 parent
04b158c0
fix(axios): 添加401响应处理以跳转登录页
在axios拦截器中添加对401响应的处理,清除用户登录信息并跳转到登录页,同时携带当前路由信息以便登录后重定向
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
src/utils/axios.js
src/utils/axios.js
View file @
80b46d6
...
...
@@ -2,12 +2,12 @@
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-28 10:17:40
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-0
3-25 15:03:55
* @LastEditTime: 2025-0
5-08 17:45:44
* @FilePath: /mlaj/src/utils/axios.js
* @Description:
*/
import
axios
from
'axios'
;
//
import router from '@/router';
import
router
from
'@/router'
;
// import qs from 'Qs'
// import { strExist } from '@/utils/tools'
...
...
@@ -43,9 +43,17 @@ axios.interceptors.request.use(
*/
axios
.
interceptors
.
response
.
use
(
response
=>
{
if
(
response
.
data
&&
response
.
data
.
code
===
401
)
{
// 清除用户登录信息
localStorage
.
removeItem
(
'currentUser'
);
// 跳转到登录页面,并携带当前路由信息
const
currentPath
=
router
.
currentRoute
.
value
.
fullPath
;
router
.
push
(
`/login?redirect=
${
encodeURIComponent
(
currentPath
)}
`
);
}
return
response
;
},
error
=>
{
// 响应错误处理
return
Promise
.
reject
(
error
);
});
...
...
Please
register
or
login
to post a comment