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
5549d2d4
Commit
5549d2d4
authored
Mar 20, 2019
by
saraka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: export 'instance' is not defined #138
parent
73b77cbc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
11 deletions
+19
-11
axios.js
src/utils/axios.js
+2
-4
request.js
src/utils/request.js
+17
-7
No files found.
src/utils/axios.js
View file @
5549d2d4
const
VueAxios
=
{
vm
:
{},
// eslint-disable-next-line no-unused-vars
install
(
Vue
,
router
=
{},
instance
)
{
install
(
Vue
,
instance
)
{
if
(
this
.
installed
)
{
return
}
...
...
@@ -31,7 +31,5 @@ const VueAxios = {
}
export
{
VueAxios
,
// eslint-disable-next-line no-undef
instance
as
axios
VueAxios
}
src/utils/request.js
View file @
5549d2d4
import
Vue
from
'vue'
import
axios
from
'axios'
import
store
from
'@/store'
import
{
VueAxios
}
from
'./axios'
import
{
VueAxios
}
from
'./axios'
import
notification
from
'ant-design-vue/es/notification'
import
{
ACCESS_TOKEN
}
from
'@/store/mutation-types'
import
{
ACCESS_TOKEN
}
from
'@/store/mutation-types'
// 创建 axios 实例
const
service
=
axios
.
create
({
...
...
@@ -16,10 +20,16 @@ const err = (error) => {
const
data
=
error
.
response
.
data
const
token
=
Vue
.
ls
.
get
(
ACCESS_TOKEN
)
if
(
error
.
response
.
status
===
403
)
{
notification
.
error
({
message
:
'Forbidden'
,
description
:
data
.
message
})
notification
.
error
({
message
:
'Forbidden'
,
description
:
data
.
message
})
}
if
(
error
.
response
.
status
===
401
)
{
notification
.
error
({
message
:
'Unauthorized'
,
description
:
'Authorization verification failed'
})
notification
.
error
({
message
:
'Unauthorized'
,
description
:
'Authorization verification failed'
})
if
(
token
)
{
store
.
dispatch
(
'Logout'
).
then
(()
=>
{
setTimeout
(()
=>
{
...
...
@@ -36,7 +46,7 @@ const err = (error) => {
service
.
interceptors
.
request
.
use
(
config
=>
{
const
token
=
Vue
.
ls
.
get
(
ACCESS_TOKEN
)
if
(
token
)
{
config
.
headers
[
'Access-Token'
]
=
token
// 让每个请求携带自定义 token 请根据实际情况自行修改
config
.
headers
[
'Access-Token'
]
=
token
// 让每个请求携带自定义 token 请根据实际情况自行修改
}
return
config
},
err
)
...
...
@@ -48,8 +58,8 @@ service.interceptors.response.use((response) => {
const
installer
=
{
vm
:
{},
install
(
Vue
,
router
=
{}
)
{
Vue
.
use
(
VueAxios
,
router
,
service
)
install
(
Vue
)
{
Vue
.
use
(
VueAxios
,
service
)
}
}
...
...
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