Skip to main content
useLazyFetch provides a wrapper around useFetch that triggers navigation before the handler is resolved by setting the lazy option to true. By default, useFetch blocks navigation until its async handler is resolved. useLazyFetch allows navigation to proceed immediately, with data being fetched in the background.

Usage

[app/pages/index.vue]
useLazyFetch has the same signature as useFetch.
Awaiting useLazyFetch only ensures the call is initialized. On client-side navigation, data may not be immediately available, and you must handle the pending state in your component’s template.
useLazyFetch is a reserved function name transformed by the compiler, so you should not name your own function useLazyFetch.

Parameters

useLazyFetch accepts the same parameters as useFetch:
string | Request | Ref<string | Request> | (() => string | Request)
required
The URL or request to fetch.
UseFetchOptions<T>
Same as useFetch options, with lazy automatically set to true. See useFetch parameters for full details.

Return Values

Returns the same AsyncData object as useFetch:
Ref<T | undefined>
The result of the asynchronous fetch.
(opts?: AsyncDataExecuteOptions) => Promise<void>
Function to manually refresh the data.
(opts?: AsyncDataExecuteOptions) => Promise<void>
Alias for refresh.
Ref<Error | undefined>
Error object if the data fetching failed.
Ref<'idle' | 'pending' | 'success' | 'error'>
Status of the data request.
() => void
Resets data to undefined, error to undefined, sets status to idle, and cancels any pending requests.

Examples

Handling Pending State

[app/pages/index.vue]

Type

useLazyFetch is equivalent to useFetch with lazy: true option set.