0c49c87e
liuqimichale
微信公众号 初始化
|
1
|
import axios from 'axios'
|
7e244ba4
刘淇
领取优惠券
|
2
|
import qs from 'qs'
|
0c49c87e
liuqimichale
微信公众号 初始化
|
3
4
|
// let _url = process.env.API_ROOT
// axios.defaults.baseURL = process.env.API_ROOT
|
7e244ba4
刘淇
领取优惠券
|
5
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
0c49c87e
liuqimichale
微信公众号 初始化
|
6
|
const service = axios.create({
|
92e91fa6
刘淇
江阴领取优惠券调接口
|
7
8
|
// baseURL:'https://bus.jycrtc.com/',
// baseURL:process.env.VUE_APP_URL,
|
331018f3
刘淇
江阴领取优惠券调接口
|
9
|
// baseURL:'',
|
0c49c87e
liuqimichale
微信公众号 初始化
|
10
|
// withCredentials: true, // send cookies when cross-domain requests
|
eae77c58
刘淇
江阴领取优惠券
|
11
|
timeout: 6000, // request timeout
|
331018f3
刘淇
江阴领取优惠券调接口
|
12
13
14
15
16
17
18
19
|
// withCredentials: false,
// crossDomain: true,
xhrFields: {
withCredentials: false
},
|
7e244ba4
刘淇
领取优惠券
|
20
21
22
23
24
25
|
// headers:{
// // 'Access-Control-Allow-Origin':'*',
// 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'
// }
|
0c49c87e
liuqimichale
微信公众号 初始化
|
26
27
28
|
})
service.interceptors.request.use(
|
eae77c58
刘淇
江阴领取优惠券
|
29
|
|
0c49c87e
liuqimichale
微信公众号 初始化
|
30
|
config => {
|
331018f3
刘淇
江阴领取优惠券调接口
|
31
32
33
|
// if (process.env.NODE_ENV === 'production'){
// if(config.requestBase=='VUE_APP_URL'){
// config.baseURL='https://bus.jycrtc.com/';
|
92e91fa6
刘淇
江阴领取优惠券调接口
|
34
|
//
|
331018f3
刘淇
江阴领取优惠券调接口
|
35
36
37
|
// }else if(config.requestBase=='VUE_APP_URL_TWO'){
// config.baseURL='https://pay.jycrtc.com/';
// }
|
92e91fa6
刘淇
江阴领取优惠券调接口
|
38
|
// }
|
eae77c58
刘淇
江阴领取优惠券
|
39
|
|
7e244ba4
刘淇
领取优惠券
|
40
41
42
|
// if(config.method === 'post'){
// config.data = qs.stringify(config.data);
// }
|
0c49c87e
liuqimichale
微信公众号 初始化
|
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
|
return config
},
error => {
// do something with request error
console.log(error) // for debug
return Promise.reject(error)
}
)
// response interceptor
service.interceptors.response.use(
response => {
const res = response.data
// if the custom code is not 20000, it is judged as an error.
if (res.code != '8888') {
return res
} else {
return res
}
},
error => {
console.log('err' + error) // for debug
return Promise.reject(error)
}
)
export default service
|