1 | ;
|
2 |
|
3 | import Vue from 'vue';
|
4 | import axios from "axios";
|
5 |
|
6 | // Full config: https://github.com/axios/axios#request-config
|
7 | // axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
8 | // axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
9 | // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
10 |
|
11 | let config = {
|
12 | // baseURL: process.env.baseURL || process.env.apiUrl || ""
|
13 | // timeout: 60 * 1000, // Timeout
|
14 | // withCredentials: true, // Check cross-site Access-Control
|
15 | };
|
16 |
|
17 | const _axios = axios.create(config);
|
18 |
|
19 | _axios.interceptors.request.use(
|
20 | function(config) {
|
21 | // Do something before request is sent
|
22 | return config;
|
23 | },
|
24 | function(error) {
|
25 | // Do something with request error
|
26 | return Promise.reject(error);
|
27 | }
|
28 | );
|
29 |
|
30 | // Add a response interceptor
|
31 | _axios.interceptors.response.use(
|
32 | function(response) {
|
33 | // Do something with response data
|
34 | return response;
|
35 | },
|
36 | function(error) {
|
37 | // Do something with response error
|
38 | return Promise.reject(error);
|
39 | }
|
40 | );
|
41 |
|
42 | Plugin.install = function(Vue, options) {
|
43 | Vue.axios = _axios;
|
44 | window.axios = _axios;
|
45 | Object.defineProperties(Vue.prototype, {
|
46 | axios: {
|
47 | get() {
|
48 | return _axios;
|
49 | }
|
50 | },
|
51 | $axios: {
|
52 | get() {
|
53 | return _axios;
|
54 | }
|
55 | },
|
56 | });
|
57 | };
|
58 |
|
59 | Vue.use(Plugin)
|
60 |
|
61 | export default Plugin;
|