From 9f217e3fcff8accedc3d6208f3dbe0e53ddca735 Mon Sep 17 00:00:00 2001 From: jahnli Date: Sun, 25 Sep 2022 00:00:19 +0800 Subject: [PATCH 1/2] feat(useAxios): add option for choosing shallowRef or ref --- 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 905e538ae74..cf0ae6799b2 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) From 862c8446ac8af47a79b8710d9fadae56c5534c29 Mon Sep 17 00:00:00 2001 From: jahnli Date: Sun, 25 Sep 2022 08:46:27 +0800 Subject: [PATCH 2/2] fix(useAxios): Fixed the Lint code format --- packages/integrations/useAxios/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/integrations/useAxios/index.ts b/packages/integrations/useAxios/index.ts index cf0ae6799b2..0ce57e51c4f 100644 --- a/packages/integrations/useAxios/index.ts +++ b/packages/integrations/useAxios/index.ts @@ -92,12 +92,12 @@ export interface UseAxiosOptions { * */ immediate?: boolean - /** + /** * Use shallowRef. * * @default true */ - shallow?: boolean + shallow?: boolean } type OverallUseAxiosReturn = StrictUseAxiosReturn | EasyUseAxiosReturn @@ -118,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,shallow:true } + let options: UseAxiosOptions = { immediate: !!argsPlaceholder, shallow: true } const isAxiosInstance = (val: any) => !!val?.request @@ -145,7 +145,7 @@ export function useAxios(...args: any[]): OverallUseAxiosRetur options = args[args.length - 1] const response = shallowRef>() - const data = options.shallow ? shallowRef() : ref(); + const data = options.shallow ? shallowRef() : ref() const isFinished = ref(false) const isLoading = ref(false) const isAborted = ref(false)