Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ant-design-pro-vue
Overview
Overview
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
tianzhuanghu
ant-design-pro-vue
Commits
86e93e7e
Commit
86e93e7e
authored
Dec 08, 2018
by
Sendya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: #22 error.response
parent
e4c85b90
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
9 deletions
+15
-9
request.js
src/utils/request.js
+15
-9
No files found.
src/utils/request.js
View file @
86e93e7e
...
@@ -13,20 +13,26 @@ const service = axios.create({
...
@@ -13,20 +13,26 @@ const service = axios.create({
const
err
=
(
error
)
=>
{
const
err
=
(
error
)
=>
{
if
(
error
.
response
)
{
if
(
error
.
response
)
{
if
(
error
.
status
===
403
)
{
let
data
=
error
.
response
.
data
notification
.
error
({
message
:
'拒绝访问'
,
description
:
'无权限,拒绝访问'
})
const
token
=
Vue
.
ls
.
get
(
ACCESS_TOKEN
)
if
(
error
.
response
.
status
===
403
)
{
notification
.
error
({
message
:
'Forbidden'
,
description
:
data
.
message
})
}
}
if
(
error
.
status
===
401
)
{
if
(
error
.
response
.
status
===
401
)
{
notification
.
error
({
message
:
'未授权'
,
description
:
'授权验证失败'
})
notification
.
error
({
message
:
'Unauthorized'
,
description
:
'Authorization verification failed'
})
store
.
dispatch
(
'Logout'
).
then
(()
=>
{
if
(
token
)
{
location
.
reload
()
store
.
dispatch
(
'Logout'
).
then
(()
=>
{
})
setTimeout
(()
=>
{
window
.
location
.
reload
()
},
1500
)
})
}
}
}
}
}
return
Promise
.
reject
(
error
)
return
Promise
.
reject
(
error
)
};
};
// request
拦截器
// request
interceptor
service
.
interceptors
.
request
.
use
(
config
=>
{
service
.
interceptors
.
request
.
use
(
config
=>
{
const
token
=
Vue
.
ls
.
get
(
ACCESS_TOKEN
)
const
token
=
Vue
.
ls
.
get
(
ACCESS_TOKEN
)
if
(
token
)
{
if
(
token
)
{
...
@@ -35,7 +41,7 @@ service.interceptors.request.use(config => {
...
@@ -35,7 +41,7 @@ service.interceptors.request.use(config => {
return
config
return
config
},
err
)
},
err
)
// response
拦截器
// response
interceptor
service
.
interceptors
.
response
.
use
((
response
)
=>
{
service
.
interceptors
.
response
.
use
((
response
)
=>
{
return
response
.
data
return
response
.
data
},
err
)
},
err
)
...
...
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