|
- import { ShallowRef, Ref } from 'vue-demi';
- import { AxiosResponse, AxiosError, RawAxiosRequestConfig, AxiosInstance } from 'axios';
-
- interface UseAxiosReturn<T, R = AxiosResponse<T>, D = any> {
- /**
- * Axios Response
- */
- response: ShallowRef<R | undefined>;
- /**
- * Axios response data
- */
- data: Ref<T | undefined>;
- /**
- * Indicates if the request has finished
- */
- isFinished: Ref<boolean>;
- /**
- * Indicates if the request is currently loading
- */
- isLoading: Ref<boolean>;
- /**
- * Indicates if the request was canceled
- */
- isAborted: Ref<boolean>;
- /**
- * Any errors that may have occurred
- */
- error: ShallowRef<AxiosError<T, D> | undefined>;
- /**
- * Aborts the current request
- */
- abort: (message?: string | undefined) => void;
- /**
- * isFinished alias
- * @deprecated use `isFinished` instead
- */
- finished: Ref<boolean>;
- /**
- * isLoading alias
- * @deprecated use `isLoading` instead
- */
- loading: Ref<boolean>;
- /**
- * isAborted alias
- * @deprecated use `isAborted` instead
- */
- aborted: Ref<boolean>;
- /**
- * abort alias
- */
- cancel: (message?: string | undefined) => void;
- /**
- * isAborted alias
- * @deprecated use `isCanceled` instead
- */
- canceled: Ref<boolean>;
- /**
- * isAborted alias
- */
- isCanceled: Ref<boolean>;
- }
- interface StrictUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
- /**
- * Manually call the axios request
- */
- execute: (url?: string | RawAxiosRequestConfig<D>, config?: RawAxiosRequestConfig<D>) => PromiseLike<StrictUseAxiosReturn<T, R, D>>;
- }
- interface EasyUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
- /**
- * Manually call the axios request
- */
- execute: (url: string, config?: RawAxiosRequestConfig<D>) => PromiseLike<EasyUseAxiosReturn<T, R, D>>;
- }
- interface UseAxiosOptions<T = any> {
- /**
- * Will automatically run axios request when `useAxios` is used
- *
- */
- immediate?: boolean;
- /**
- * Use shallowRef.
- *
- * @default true
- */
- shallow?: boolean;
- /**
- * Callback when error is caught.
- */
- onError?: (e: unknown) => void;
- /**
- * Callback when success is caught.
- */
- onSuccess?: (data: T) => void;
- }
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: RawAxiosRequestConfig<D>, options?: UseAxiosOptions<T>): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, instance?: AxiosInstance, options?: UseAxiosOptions<T>): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(url: string, config: RawAxiosRequestConfig<D>, instance: AxiosInstance, options?: UseAxiosOptions<T>): StrictUseAxiosReturn<T, R, D> & PromiseLike<StrictUseAxiosReturn<T, R, D>>;
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: RawAxiosRequestConfig<D>): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
- declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: RawAxiosRequestConfig<D>, instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
-
- export { EasyUseAxiosReturn, StrictUseAxiosReturn, UseAxiosOptions, UseAxiosReturn, useAxios };
|