index.js
1.65 KB
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
71
72
73
74
75
76
77
import axios from "axios";
import {url,error,success} from "./config";
let config = {
// baseURL:process.env.VUE_APP_baseURL,// || process.env.apiUrl || ""
// timeout: 60 * 1000, // Timeout
// withCredentials: true, // Check cross-site Access-Control
headers: {
}
};
const _axios = axios.create(config);
_axios.interceptors.request.use(
function (config) {
// debugger
// Do something before request is sent
return config;
},
function (error) {
// Do something with request error
return Promise.reject(error);
}
);
// Add a response interceptor
_axios.interceptors.response.use(
function (response) {
// debugger;
// Do something with response data
if ("data" in response) {
// debugger;
return config.success(response.data)
}
// debugger;
console.log("非标准输出!")
return response;
},
function (error) {
// Do something with response error
return Promise.reject(error);
}
);
export default {
GET(target,params={}){
return _axios.get((target),{params})
},
POST(target,params={}){
return _axios.post((target),params)
}
}
// Plugin.install = function (Vue, options) {
// Vue.axios = _axios;
// window.axios = _axios;
// Object.defineProperties(Vue.prototype, {
// axios: {
// get() {
// return _axios;
// }
// },
// $axios: {
// get() {
// return _axios;
// }
// },
// });
// };
// Vue.use(Plugin)
// export default Plugin;