Skip to content

Commit

Permalink
feat(useAxios): add option for choosing shallowRef or ref (#2251)
Browse files Browse the repository at this point in the history
* feat(useAxios): add option for choosing shallowRef or ref

* fix(useAxios): Fixed the Lint code format
  • Loading branch information
jahnli committed Sep 25, 2022
1 parent 4b72d97 commit d065d2f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/integrations/useAxios/index.ts
Expand Up @@ -92,6 +92,12 @@ export interface UseAxiosOptions {
*
*/
immediate?: boolean
/**
* Use shallowRef.
*
* @default true
*/
shallow?: boolean
}
type OverallUseAxiosReturn<T, D> = StrictUseAxiosReturn<T, D> | EasyUseAxiosReturn<T, D>

Expand All @@ -112,7 +118,7 @@ export function useAxios<T = any, D = any>(...args: any[]): OverallUseAxiosRetur
const argsPlaceholder = isString(url) ? 1 : 0
let defaultConfig: AxiosRequestConfig<D> = {}
let instance: AxiosInstance = axios
let options: UseAxiosOptions = { immediate: !!argsPlaceholder }
let options: UseAxiosOptions = { immediate: !!argsPlaceholder, shallow: true }

const isAxiosInstance = (val: any) => !!val?.request

Expand All @@ -139,7 +145,7 @@ export function useAxios<T = any, D = any>(...args: any[]): OverallUseAxiosRetur
options = args[args.length - 1]

const response = shallowRef<AxiosResponse<T>>()
const data = shallowRef<T>()
const data = options.shallow ? shallowRef<T>() : ref<T>()
const isFinished = ref(false)
const isLoading = ref(false)
const isAborted = ref(false)
Expand Down

0 comments on commit d065d2f

Please sign in to comment.