1
1
import Vue from 'vue'
2
2
import axios from 'axios'
3
3
import store from '@/store'
4
- import { VueAxios } from './axios'
4
+ import {
5
+ VueAxios
6
+ } from './axios'
5
7
import notification from 'ant-design-vue/es/notification'
6
- import { ACCESS_TOKEN } from '@/store/mutation-types'
8
+ import {
9
+ ACCESS_TOKEN
10
+ } from '@/store/mutation-types'
7
11
8
12
// 创建 axios 实例
9
13
const service = axios . create ( {
@@ -16,10 +20,16 @@ const err = (error) => {
16
20
const data = error . response . data
17
21
const token = Vue . ls . get ( ACCESS_TOKEN )
18
22
if ( error . response . status === 403 ) {
19
- notification . error ( { message : 'Forbidden' , description : data . message } )
23
+ notification . error ( {
24
+ message : 'Forbidden' ,
25
+ description : data . message
26
+ } )
20
27
}
21
28
if ( error . response . status === 401 ) {
22
- notification . error ( { message : 'Unauthorized' , description : 'Authorization verification failed' } )
29
+ notification . error ( {
30
+ message : 'Unauthorized' ,
31
+ description : 'Authorization verification failed'
32
+ } )
23
33
if ( token ) {
24
34
store . dispatch ( 'Logout' ) . then ( ( ) => {
25
35
setTimeout ( ( ) => {
@@ -36,7 +46,7 @@ const err = (error) => {
36
46
service . interceptors . request . use ( config => {
37
47
const token = Vue . ls . get ( ACCESS_TOKEN )
38
48
if ( token ) {
39
- config . headers [ 'Access-Token' ] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
49
+ config . headers [ 'Access-Token' ] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
40
50
}
41
51
return config
42
52
} , err )
@@ -48,8 +58,8 @@ service.interceptors.response.use((response) => {
48
58
49
59
const installer = {
50
60
vm : { } ,
51
- install ( Vue , router = { } ) {
52
- Vue . use ( VueAxios , router , service )
61
+ install ( Vue ) {
62
+ Vue . use ( VueAxios , service )
53
63
}
54
64
}
55
65
0 commit comments