Skip to content

Commit

Permalink
fix(useAxios): fix cancelToken (#2728)
Browse files Browse the repository at this point in the history
Co-authored-by: 丶远方 <pantengyang@cybstar.com>
  • Loading branch information
Alfred-Skyblue and 丶远方 committed Feb 16, 2023
1 parent b9f449b commit 7ad5166
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/integrations/useAxios/index.ts
Expand Up @@ -161,12 +161,15 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
const isAborted = ref(false)
const error = shallowRef<AxiosError<T>>()

const cancelToken: CancelTokenSource = axios.CancelToken.source()
const cancelTokenSource = axios.CancelToken.source
let cancelToken: CancelTokenSource = cancelTokenSource()

const abort = (message?: string) => {
if (isFinished.value || !isLoading.value)
return

cancelToken.cancel(message)
cancelToken = cancelTokenSource()
isAborted.value = true
isLoading.value = false
isFinished.value = false
Expand Down Expand Up @@ -195,7 +198,7 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
isFinished.value = true
return { then }
}

abort()
loading(true)
instance(_url, { ...defaultConfig, ...typeof executeUrl === 'object' ? executeUrl : config, cancelToken: cancelToken.token })
.then((r: any) => {
Expand Down

0 comments on commit 7ad5166

Please sign in to comment.