8000 feat(useAxios): support `abortPrevious` option (#3735) · vueuse/vueuse@b94de90 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit b94de90

Browse files
jahnliantfu
andauthored
feat(useAxios): support abortPrevious option (#3735)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent 5025e3a commit b94de90

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/integrations/useAxios/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ export interface UseAxiosOptions<T = any> {
7676
*/
7777
shallow?: boolean
7878

79+
/**
80+
* Abort previous request when a new request is made.
81+
*
82+
* @default true
83+
*/
84+
abortPrevious?: boolean
85+
7986
/**
8087
* Callback when error is caught.
8188
*/
@@ -121,6 +128,7 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
121128
const defaultOptions: UseAxiosOptions<T> = {
122129
immediate: !!argsPlaceholder,
123130
shallow: true,
131+
abortPrevious: true,
124132
}
125133
let defaultConfig: AxiosRequestConfig<D> = {}
126134
let instance: AxiosInstance = axios
@@ -218,7 +226,10 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
218226
return promise
219227
}
220228
resetData()
221-
abort()
229+
230+
if (options.abortPrevious)
231+
abort()
232+
222233
loading(true)
223234

224235
executeCounter += 1

0 commit comments

Comments
 (0)
0