Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mould-vuecli3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lhfe
mould-vuecli3
Commits
9ebf1fe1
Commit
9ebf1fe1
authored
Sep 28, 2020
by
lipengcheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
d11265df
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
index.js
src/plugins/axios/index.js
+8
-2
No files found.
src/plugins/axios/index.js
View file @
9ebf1fe1
...
...
@@ -2,7 +2,7 @@
// 如果设置了全局拦截器,想取消实例中发出的请求,必须先移除全局拦截器,实例中配置的config.cancelToken属性才会生效
import
axios
from
'axios'
import
handleStatus
from
'@/plugins/axios/axios.handleStatus.js'
//
import handleStatus from '@/plugins/axios/axios.handleStatus.js'
import
setOptions
from
'@/plugins/axios/axios.setOptions.js'
// import store from '@/store/index'
// import router from '@/router/index.js'
...
...
@@ -51,13 +51,19 @@ const responseInterceptors = request.interceptors.response.use(
(
response
)
=>
{
const
{
config
}
=
response
pendingPool
.
delete
(
config
.
url
)
return
Promise
.
resolve
(
handleStatus
(
response
))
if
(
response
.
status
===
200
)
{
return
Promise
.
resolve
(
response
)
}
else
{
return
Promise
.
reject
(
response
)
}
// return Promise.resolve(handleStatus(response))
},
// 对响应错误做点什么
(
err
)
=>
{
console
.
log
(
'响应拦截err:'
,
err
)
console
.
log
(
'pendingPool2:'
,
pendingPool
)
console
.
log
(
'axios.isCancel(err):'
,
axios
.
isCancel
(
err
))
console
.
log
(
'err.response.status:'
,
err
.
response
.
status
)
// 错误信息err传入isCancel方法,可以判断请求是否被取消
if
(
axios
.
isCancel
(
err
))
{
throw
new
axios
.
Cancel
(
err
.
message
||
'请求被主动取消'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment