|
1 |
| -"use strict"; |
| 1 | +'use strict'; |
2 | 2 |
|
3 |
| -import vue from 'vue'; |
4 |
| -import axios, { AxiosInstance } from "axios"; |
| 3 | +import Vue from 'vue'; |
| 4 | +import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; |
5 | 5 |
|
6 | 6 | // Full config: https://github.com/axios/axios#request-config
|
7 | 7 | // axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
8 | 8 | // axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
9 | 9 | // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
10 | 10 |
|
11 |
| -let config = { |
| 11 | +const config = { |
12 | 12 | // baseURL: process.env.baseURL || process.env.apiUrl || ""
|
13 | 13 | // timeout: 60 * 1000, // Timeout
|
14 | 14 | // withCredentials: true, // Check cross-site Access-Control
|
15 | 15 | };
|
16 | 16 |
|
| 17 | +// tslint:disable-next-line: variable-name |
17 | 18 | const _axios = axios.create(config);
|
18 | 19 |
|
19 | 20 | _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 |
| - } |
| 21 | + // Do something before request is sent |
| 22 | + (conf: AxiosRequestConfig) => conf, |
| 23 | + // Do something with request error |
| 24 | + (error: any) => Promise.reject(error), |
28 | 25 | );
|
29 | 26 |
|
30 | 27 | // Add a response interceptor
|
31 | 28 | _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 |
| - } |
| 29 | + // Do something before request is sent |
| 30 | + (response: any) => response, |
| 31 | + // Do something with response error |
| 32 | + (error: any) => Promise.reject(error), |
40 | 33 | );
|
41 | 34 |
|
42 |
| -function AxiosPlugin(Vue: typeof vue, options?: any): void { |
43 |
| - Vue.prototype.$axios = _axios; |
| 35 | +function AxiosPlugin(vue: typeof Vue, options?: any): void { |
| 36 | + vue.prototype.$axios = _axios; |
44 | 37 | }
|
45 | 38 |
|
46 | 39 | declare module 'vue/types/vue' {
|
47 |
| - interface Vue { |
48 |
| - $axios: AxiosInstance; |
49 |
| - } |
| 40 | + interface Vue { |
| 41 | + $axios: AxiosInstance; |
| 42 | + } |
50 | 43 | }
|
51 | 44 |
|
52 |
| -vue.use(AxiosPlugin) |
53 |
| - |
| 45 | +Vue.use(AxiosPlugin); |
54 | 46 |
|
55 | 47 | export default Plugin;
|
0 commit comments