From d065d2fc1eddd55fbaa8526f4f16275f17dc69b6 Mon Sep 17 00:00:00 2001 From: jahnli Date: Mon, 26 Sep 2022 03:27:18 +0800 Subject: [PATCH] feat(useAxios): add option for choosing shallowRef or ref (#2251) * feat(useAxios): add option for choosing shallowRef or ref * fix(useAxios): Fixed the Lint code format --- packages/integrations/useAxios/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/integrations/useAxios/index.ts b/packages/integrations/useAxios/index.ts index 1e37e6a5772..4cce277a487 100644 --- a/packages/integrations/useAxios/index.ts +++ b/packages/integrations/useAxios/index.ts @@ -92,6 +92,12 @@ export interface UseAxiosOptions { * */ immediate?: boolean + /** + * Use shallowRef. + * + * @default true + */ + shallow?: boolean } type OverallUseAxiosReturn = StrictUseAxiosReturn | EasyUseAxiosReturn @@ -112,7 +118,7 @@ export function useAxios(...args: any[]): OverallUseAxiosRetur const argsPlaceholder = isString(url) ? 1 : 0 let defaultConfig: AxiosRequestConfig = {} let instance: AxiosInstance = axios - let options: UseAxiosOptions = { immediate: !!argsPlaceholder } + let options: UseAxiosOptions = { immediate: !!argsPlaceholder, shallow: true } const isAxiosInstance = (val: any) => !!val?.request @@ -139,7 +145,7 @@ export function useAxios(...args: any[]): OverallUseAxiosRetur options = args[args.length - 1] const response = shallowRef>() - const data = shallowRef() + const data = options.shallow ? shallowRef() : ref() const isFinished = ref(false) const isLoading = ref(false) const isAborted = ref(false)