Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
vue-flow-editor
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
2023-12-03 18:15:09 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
77c7878b823144514fe14d5248883cb7b807e8b6
77c7878b
1 parent
478d3d50
优化登录失效后中断后续请求
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
doc/axios.js
doc/axios.js
View file @
77c7878
/*
* @Date: 2023-10-27 11:12:24
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-12-0
1 15:38
:32
* @LastEditTime: 2023-12-0
3 18:13
:32
* @FilePath: /vue-flow-editor/doc/axios.js
* @Description: 文件描述
*/
...
...
@@ -23,6 +23,10 @@ const parseQueryString = url => {
return
json
;
}
// 获取CancelToken
const
CancelToken
=
axios
.
CancelToken
;
const
source
=
CancelToken
.
source
();
/**
* @description 请求拦截器
*/
...
...
@@ -37,6 +41,8 @@ axios.interceptors.request.use(
*/
// 绑定默认请求头
config
.
params
=
{
...
config
.
params
,
timestamp
};
// 全局添加cancelToken
config
.
cancelToken
=
source
.
token
;
return
config
;
},
error
=>
{
...
...
@@ -50,8 +56,11 @@ axios.interceptors.request.use(
axios
.
interceptors
.
response
.
use
(
response
=>
{
// 默认显示错误提示
response
.
data
.
show
=
true
;
//
response.data.show = true;
if
(
response
.
data
.
msg
===
'登录失效'
)
{
// 某个请求的响应满足特定条件的情况下,取消【其他正在进行的请求】
source
.
cancel
();
//
ElMessageBox
.
alert
(
'登录失效!将跳转到登录页面。'
,
'温馨提示'
,
{
confirmButtonText
:
'确定'
,
callback
:
action
=>
{
...
...
Please
register
or
login
to post a comment