版博士V2.0程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

103 řádky
3.6 KiB

  1. import { ShallowRef, Ref } from 'vue-demi';
  2. import { AxiosResponse, AxiosError, RawAxiosRequestConfig, AxiosInstance } from 'axios';
  3. interface UseAxiosReturn<T, R = AxiosResponse<T>, D = any> {
  4. /**
  5. * Axios Response
  6. */
  7. response: ShallowRef<R | undefined>;
  8. /**
  9. * Axios response data
  10. */
  11. data: Ref<T | undefined>;
  12. /**
  13. * Indicates if the request has finished
  14. */
  15. isFinished: Ref<boolean>;
  16. /**
  17. * Indicates if the request is currently loading
  18. */
  19. isLoading: Ref<boolean>;
  20. /**
  21. * Indicates if the request was canceled
  22. */
  23. isAborted: Ref<boolean>;
  24. /**
  25. * Any errors that may have occurred
  26. */
  27. error: ShallowRef<AxiosError<T, D> | undefined>;
  28. /**
  29. * Aborts the current request
  30. */
  31. abort: (message?: string | undefined) => void;
  32. /**
  33. * isFinished alias
  34. * @deprecated use `isFinished` instead
  35. */
  36. finished: Ref<boolean>;
  37. /**
  38. * isLoading alias
  39. * @deprecated use `isLoading` instead
  40. */
  41. loading: Ref<boolean>;
  42. /**
  43. * isAborted alias
  44. * @deprecated use `isAborted` instead
  45. */
  46. aborted: Ref<boolean>;
  47. /**
  48. * abort alias
  49. */
  50. cancel: (message?: string | undefined) => void;
  51. /**
  52. * isAborted alias
  53. * @deprecated use `isCanceled` instead
  54. */
  55. canceled: Ref<boolean>;
  56. /**
  57. * isAborted alias
  58. */
  59. isCanceled: Ref<boolean>;
  60. }
  61. interface StrictUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
  62. /**
  63. * Manually call the axios request
  64. */
  65. execute: (url?: string | RawAxiosRequestConfig<D>, config?: RawAxiosRequestConfig<D>) => PromiseLike<StrictUseAxiosReturn<T, R, D>>;
  66. }
  67. interface EasyUseAxiosReturn<T, R, D> extends UseAxiosReturn<T, R, D> {
  68. /**
  69. * Manually call the axios request
  70. */
  71. execute: (url: string, config?: RawAxiosRequestConfig<D>) => PromiseLike<EasyUseAxiosReturn<T, R, D>>;
  72. }
  73. interface UseAxiosOptions<T = any> {
  74. /**
  75. * Will automatically run axios request when `useAxios` is used
  76. *
  77. */
  78. immediate?: boolean;
  79. /**
  80. * Use shallowRef.
  81. *
  82. * @default true
  83. */
  84. shallow?: boolean;
  85. /**
  86. * Callback when error is caught.
  87. */
  88. onError?: (e: unknown) => void;
  89. /**
  90. * Callback when success is caught.
  91. */
  92. onSuccess?: (data: T) => void;
  93. }
  94. 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>>;
  95. 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>>;
  96. 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>>;
  97. declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: RawAxiosRequestConfig<D>): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
  98. declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
  99. declare function useAxios<T = any, R = AxiosResponse<T>, D = any>(config?: RawAxiosRequestConfig<D>, instance?: AxiosInstance): EasyUseAxiosReturn<T, R, D> & PromiseLike<EasyUseAxiosReturn<T, R, D>>;
  100. export { EasyUseAxiosReturn, StrictUseAxiosReturn, UseAxiosOptions, UseAxiosReturn, useAxios };