β¬ οΈ Back to Table of Contents
π useAxios¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 9 |
| π¦ Imports | 11 |
| β‘ Async/Await Patterns | 2 |
| π Interfaces | 5 |
| π Type Aliases | 2 |
π Table of Contents¶
π οΈ File Location:¶
π packages/integrations/useAxios/index.ts
π¦ Imports¶
| Name | Source |
|---|---|
AxiosInstance |
axios |
AxiosRequestConfig |
axios |
AxiosResponse |
axios |
Ref |
vue |
ShallowRef |
vue |
noop |
@vueuse/shared |
until |
@vueuse/shared |
AxiosError |
axios |
axios |
axios |
deepRef |
vue |
shallowRef |
vue |
Async/Await Patterns¶
| Type | Function | Await Expressions | Promise Chains |
|---|---|---|---|
| promise-chain | waitUntilFinished |
none | new Promise(...), until(isFinished).toBe(true).then |
| promise-chain | execute |
none | instance(_url, { ...defaultConfig, ...typeof executeUrl === 'object' ? execut... |
Functions¶
useAxios(url: string, config: AxiosRequestConfig<D>, options: O): StrictUseAxiosReturn<T, R, D, O> & Promise<StrictUseAxiosRe⦶
Parameters:
urlstringconfigAxiosRequestConfig<D>optionsO
Returns: StrictUseAxiosReturn<T, R, D, O> & Promise<StrictUseAxiosReturn<T, R, D, O>>
Code
Internal helpers¶
Declared inside another function in this file.
isAxiosInstance(val: any): boolean¶
Parameters:
valany
Returns: boolean
abort(message: string): void¶
Parameters:
messagestring
Returns: void
Calls:
abortController.abort
Code
loading(loading: boolean): void¶
Parameters:
loadingboolean
Returns: void
resetData(): void¶
Returns: void
waitUntilFinished(): Promise<OverallUseAxiosReturn<T, R, D>>¶
Returns: Promise<OverallUseAxiosReturn<T, R, D>>
Code
then(args: [onfulfilled?: (value: OverallUseAxiosRβ¦): Promise<TResult1 | TResult2>¶
Parameters:
args[onfulfilled?: (value: OverallUseAxiosReturn<T, R, D>) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<...>]
Returns: Promise<TResult1 | TResult2>
Calls:
waitUntilFinished().then
catch(args: [onrejected?: (reason: any) => TResult β¦): Promise<OverallUseAxiosReturn<T, R, D> | TResult>¶
Parameters:
args[onrejected?: (reason: any) => TResult | PromiseLike<TResult>]
Returns: Promise<OverallUseAxiosReturn<T, R, D> | TResult>
Calls:
waitUntilFinished().catch
execute(executeUrl: string | AxiosRequestConfig<D> | undefiβ¦, config: AxiosRequestConfig<D>): Promise<OverallUseAxiosReturn<T, R, D>>¶
Parameters:
executeUrlstring | AxiosRequestConfig<D> | undefinedconfigAxiosRequestConfig<D>
Returns: Promise<OverallUseAxiosReturn<T, R, D>>
Calls:
resetDataabortloadinginstance(_url, { ...defaultConfig, ...typeof executeUrl === 'object' ? executeUrl : config, signal: abortController.signal }) .then((r: any) => { if (isAborted.value) return response.value = r const result = r?.data data.value = result onSuccess(result) }) .catch((e: any) => { error.value = e onError(e) }) .finallyoptions.onFinish
Code
(executeUrl: string | AxiosRequestConfig<D> | undefined = url, config: AxiosRequestConfig<D> = {}) => {
error.value = undefined
const _url = typeof executeUrl === 'string'
? executeUrl
: url ?? config.url
if (_url === undefined) {
error.value = new AxiosError(AxiosError.ERR_INVALID_URL)
isFinished.value = true
return promise
}
resetData()
if (options.abortPrevious !== false)
abort()
loading(true)
executeCounter += 1
const currentExecuteCounter = executeCounter
isAborted.value = false
instance(_url, { ...defaultConfig, ...typeof executeUrl === 'object' ? executeUrl : config, signal: abortController.signal })
.then((r: any) => {
if (isAborted.value)
return
response.value = r
const result = r?.data
data.value = result
onSuccess(result)
})
.catch((e: any) => {
error.value = e
onError(e)
})
.finally(() => {
options.onFinish?.()
if (currentExecuteCounter === executeCounter)
loading(false)
})
return promise
}
Interfaces¶
UseAxiosReturn<T, R = AxiosResponse<T>, _D = any, O extends UseAxiosOptions = UseAxiosOptions<T>>¶
Interface Code
export interface UseAxiosReturn<T, R = AxiosResponse<T>, _D = any, O extends UseAxiosOptions = UseAxiosOptions<T>> {
/**
* Axios Response
*/
response: ShallowRef<R | undefined>
/**
* Axios response data
*/
data: O extends UseAxiosOptionsWithInitialData<T> ? Ref<T> : Ref<T | undefined>
/**
* Indicates if the request has finished
*/
isFinished: Ref<boolean>
/**
* Indicates if the request is currently loading
*/
isLoading: Ref<boolean>
/**
* Indicates if the request was canceled
*/
isAborted: Ref<boolean>
/**
* Any errors that may have occurred
*/
error: ShallowRef<unknown | undefined>
/**
* Aborts the current request
*/
abort: (message?: string | undefined) => void
/**
* Alias to `abort`
*/
cancel: (message?: string | undefined) => void
/**
* Alias to `isAborted`
*/
isCanceled: Ref<boolean>
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
response |
ShallowRef<R \| undefined> |
β | not shown |
data |
O extends UseAxiosOptionsWithInitialData<T> ? Ref<T> : Ref<T \| undefined> |
β | not shown |
isFinished |
Ref<boolean> |
β | not shown |
isLoading |
Ref<boolean> |
β | not shown |
isAborted |
Ref<boolean> |
β | not shown |
error |
ShallowRef<unknown \| undefined> |
β | not shown |
abort |
(message?: string \| undefined) => void |
β | not shown |
cancel |
(message?: string \| undefined) => void |
β | not shown |
isCanceled |
Ref<boolean> |
β | not shown |
StrictUseAxiosReturn<T, R, D, O extends UseAxiosOptions = UseAxiosOptions<T>>¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
execute |
(url?: string \| AxiosRequestConfig<D>, config?: AxiosRequestConfig<D>) => Pr... |
β | not shown |
EasyUseAxiosReturn<T, R, D>¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
execute |
(url: string, config?: AxiosRequestConfig<D>) => Promise<EasyUseAxiosReturn<T... |
β | not shown |
UseAxiosOptionsBase<T = any>¶
Interface Code
export interface UseAxiosOptionsBase<T = any> {
/**
* Will automatically run axios request when `useAxios` is used
*
*/
immediate?: boolean
/**
* Use shallowRef.
*
* @default true
*/
shallow?: boolean
/**
* Abort previous request when a new request is made.
*
* @default true
*/
abortPrevious?: boolean
/**
* Callback when error is caught.
*/
onError?: (e: unknown) => void
/**
* Callback when success is caught.
*/
onSuccess?: (data: T) => void
/**
* Sets the state to initialState before executing the promise.
*/
resetOnExecute?: boolean
/**
* Callback when request is finished.
*/
onFinish?: () => void
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
immediate |
boolean |
β | not shown |
shallow |
boolean |
β | not shown |
abortPrevious |
boolean |
β | not shown |
onError |
(e: unknown) => void |
β | not shown |
onSuccess |
(data: T) => void |
β | not shown |
resetOnExecute |
boolean |
β | not shown |
onFinish |
() => void |
β | not shown |
UseAxiosOptionsWithInitialData<T>¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
initialData |
T |
β | not shown |
Type Aliases¶
UseAxiosOptions<T = any>¶
OverallUseAxiosReturn<T, R, D>¶
Generated by Syntax Scribe