|
@@ -1,11 +1,19 @@
|
1
|
1
|
import axios from 'axios'
|
2
|
2
|
import { ElMessage } from 'element-plus';
|
3
|
3
|
|
4
|
|
-// 请求超时时间
|
5
|
|
-axios.defaults.timeout = 10000
|
|
4
|
+
|
|
5
|
+export const service = axios.create({
|
|
6
|
+ baseURL: window.g.BASE_API,
|
|
7
|
+ // withCredentials: true, // 跨域请求时发送 cookies
|
|
8
|
+ timeout: 10000
|
|
9
|
+
|
|
10
|
+})
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
6
|
14
|
|
7
|
15
|
// 请求拦截器
|
8
|
|
-axios.interceptors.request.use(
|
|
16
|
+service.interceptors.request.use(
|
9
|
17
|
config => {
|
10
|
18
|
// const token = session.get('Token');
|
11
|
19
|
// token && (config.headers.Authorization = token);
|
|
@@ -20,7 +28,7 @@ axios.interceptors.request.use(
|
20
|
28
|
)
|
21
|
29
|
// 响应请求拦截器
|
22
|
30
|
|
23
|
|
-axios.interceptors.response.use(
|
|
31
|
+service.interceptors.response.use(
|
24
|
32
|
response => {
|
25
|
33
|
// console.log("response", response)
|
26
|
34
|
if (response.status === 200) {
|
|
@@ -51,7 +59,7 @@ axios.interceptors.response.use(
|
51
|
59
|
|
52
|
60
|
export function get(url, params) {
|
53
|
61
|
return new Promise((resolve, reject) => {
|
54
|
|
- axios.get(url, {
|
|
62
|
+ service.get(url, {
|
55
|
63
|
params
|
56
|
64
|
}).then(res => {
|
57
|
65
|
resolve(res)
|
|
@@ -62,9 +70,8 @@ export function get(url, params) {
|
62
|
70
|
}
|
63
|
71
|
|
64
|
72
|
export function post(url, params) {
|
65
|
|
-
|
66
|
73
|
return new Promise((resolve, reject) => {
|
67
|
|
- axios.post(url, {
|
|
74
|
+ service.post(url, {
|
68
|
75
|
data: params
|
69
|
76
|
}).then(res => {
|
70
|
77
|
resolve(res)
|