-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathindex.js
70 lines (67 loc) · 1.56 KB
/
index.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* @Author: luox-e
* @Date: 2019-02-19 14:29:36
* @Last Modified by: glodon
* @Last Modified time: 2019-02-19 14:43:08
*/
import axios from 'axios'
import {
MessageBox
} from 'element-ui'
let api = '/api'
if (process.env.NODE_ENV === 'development') {
api = '/api/'
}
const baseURL = api
const Axios = axios.create({
baseURL: baseURL, // 因为我本地做了反向代理
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
})
Axios.interceptors.response.use(
function (response) {
// 返回响应时做一些处理
if (
response.request.responseURL &&
response.request.responseURL.indexOf(
'Services/Identification/Server/login.ashx'
) > 0
) {
this.$router.push({
path: '/login'
})
// window.location = '/Services/Identification/Server/Login.aspx'
} else {
if (response) {
return response.data
} else {
const msgConfig = {
title: '系统错误',
message: response.data.ResultDetailMsg
}
MessageBox(msgConfig)
}
}
},
function (error) {
if (error.response) {
// const msgConfig = {
// title: '请求错误',
// message: error.response.status
// }
// MessageBox(msgConfig)
}
// 当响应异常时做一些处理
return Promise.reject(error)
}
)
// 对axios的实例重新封装成一个plugin ,方便 Vue.use(xxxx)
export default {
install: function (Vue, Option) {
Object.defineProperty(Vue.prototype, '$http', {
value: Axios
})
},
baseURL
}