UNPKG

1.36 kBJavaScriptView Raw
1"use strict";
2
3import Vue from 'vue';
4import 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
11let config = {
12 // baseURL: process.env.baseURL || process.env.apiUrl || ""
13 // timeout: 60 * 1000, // Timeout
14 // withCredentials: true, // Check cross-site Access-Control
15};
16
17const _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
42Plugin.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
59Vue.use(Plugin)
60
61export default Plugin;