UNPKG

2.52 kBTypeScriptView Raw
1import { AxiosError, AxiosRequestConfig, AxiosResponse, AxiosStatic } from 'axios'
2import { IAxiosRetryConfig } from 'axios-retry'
3import Vue from 'vue'
4import './vuex'
5
6interface NuxtAxiosInstance extends AxiosStatic {
7 $request<T = any>(config: AxiosRequestConfig): Promise<T>
8 $get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>
9 $delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>
10 $head<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>
11 $options<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>
12 $post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>
13 $put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>
14 $patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>
15
16 setBaseURL(baseURL: string): void
17 setHeader(name: string, value?: string | false, scopes?: string | string[]): void
18 setToken(token: string | false, type?: string, scopes?: string | string[]): void
19
20 onRequest(callback: (config: AxiosRequestConfig) => void): void
21 onResponse<T = any>(callback: (response: AxiosResponse<T>) => void): void
22 onError(callback: (error: AxiosError) => void): void
23 onRequestError(callback: (error: AxiosError) => void): void
24 onResponseError(callback: (error: AxiosError) => void): void
25}
26
27interface AxiosOptions {
28 baseURL?: string,
29 browserBaseURL?: string,
30 credentials?: boolean,
31 debug?: boolean,
32 host?: string,
33 prefix?: string,
34 progress?: boolean,
35 proxyHeaders?: boolean,
36 proxyHeadersIgnore?: string[],
37 proxy?: boolean,
38 port?: string | number,
39 retry?: boolean | IAxiosRetryConfig,
40 https?: boolean,
41 headers?: {
42 common?: Record<string, string>,
43 delete?: Record<string, string>,
44 get?: Record<string, string>,
45 head?: Record<string, string>,
46 post?: Record<string, string>,
47 put?: Record<string, string>,
48 patch?: Record<string, string>,
49 },
50}
51
52declare module 'axios' {
53 interface AxiosRequestConfig {
54 progress?: boolean;
55 }
56}
57
58declare module '@nuxt/vue-app' {
59 interface Context {
60 $axios: NuxtAxiosInstance
61 }
62 interface NuxtAppOptions {
63 $axios: NuxtAxiosInstance
64 }
65}
66
67// Nuxt 2.9+
68declare module '@nuxt/types' {
69 interface Context {
70 $axios: NuxtAxiosInstance
71 }
72
73 interface NuxtAppOptions {
74 $axios: NuxtAxiosInstance
75 }
76
77 interface Configuration {
78 axios?: AxiosOptions
79 }
80}
81
82declare module 'vue/types/vue' {
83 interface Vue {
84 $axios: NuxtAxiosInstance
85 }
86}
87
\No newline at end of file