Skip to content

Commit

Permalink
feat(useAxios): support abortPrevious option (vueuse#3735)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
2 people authored and noook committed Mar 26, 2024
1 parent 5330a65 commit 6cda3c2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/integrations/useAxios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export interface UseAxiosOptions<T = any> {
*/
shallow?: boolean

/**
* Abort previous request when a new request is made.
*
* @default true
*/
abortPrevious?: boolean

/**
* Callback when error is caught.
*/
Expand Down Expand Up @@ -121,6 +128,7 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
const defaultOptions: UseAxiosOptions<T> = {
immediate: !!argsPlaceholder,
shallow: true,
abortPrevious: true,
}
let defaultConfig: AxiosRequestConfig<D> = {}
let instance: AxiosInstance = axios
Expand Down Expand Up @@ -218,7 +226,10 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
return promise
}
resetData()
abort()

if (options.abortPrevious)
abort()

loading(true)

executeCounter += 1
Expand Down

0 comments on commit 6cda3c2

Please sign in to comment.