1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
| import axios from 'axios'
| import { Message,MessageBox} from 'element-ui'
| import store from '../store'
|
| //请求地址
| axios.defaults.baseURL = 'http://127.0.0.1:8998'
|
| //设置超时时间
| axios.defaults.timeout = 50000
| // post请求头
| axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
| axios.defaults.withCredentials = true
|
|
| // 响应拦截器(处理响应数据)
| axios.interceptors.response.use(
| (res) => {
| const ret = res.data
| if(ret.status !== 200){
| if(ret.status == 101){
| MessageBox.confirm(ret.msg, '系统提示', {
| confirmButtonText: '重新登录',
| cancelButtonText: '取消',
| type: 'warning'
| }
| ).then(() => {
| store.dispatch('logout').then(() => {
| location.href = '/';
| })
| })
| }else{
| Message({
| showClose: true,
| message: ret.msg || 'Server error',
| type: 'error',
| duration: 2000
| })
| }
| reject(ret.msg)
| }
| return res
| },
| (error) => {
| Message({
| showClose: true,
| message: error.message,
| type: 'error',
| duration: 2000
| })
| return Promise.reject(error);
| }
| );
|
|