Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dvlkit/nuxe/llms.txt
Use this file to discover all available pages before exploring further.
useAsyncData is Nuxe’s core data-fetching primitive. On the server it runs your async handler, stores the result in the SSR payload, and ships it to the browser. On the client the payload is read back and the handler is not called again — eliminating duplicate network requests across the hydration boundary. Subsequent client-side navigations re-run the handler normally.
Every
useAsyncData call is deduplicated by key. Two calls with the same key in the same request share a single in-flight promise and a single serialized result. Keys are also used as the payload property name during SSR hydration, so they must be unique across the app.Signature
AsyncDataKey
The key argument accepts three forms:
Ref<string> or getter function is supplied, useAsyncData watches the resolved value and automatically re-fetches whenever it changes.
Parameters
A unique identifier for this async data entry. Used for SSR payload serialization, client-side hydration, and deduplication. When
key is a Ref or a getter function, the resolved string value is watched — a key change clears data and triggers a fresh fetch.An async function that returns the data. Executed on the server during SSR (unless
server: false) and on the client for any fetch that cannot be hydrated from the SSR payload.Optional configuration object. All fields are optional.
A factory function that returns the initial value of
data before the handler resolves. Useful to avoid null checks in templates while the first fetch is in-flight.Set to
false to skip running the handler during SSR. The fetch will happen on the client after hydration instead.When
true, the handler runs after the component mounts rather than blocking navigation. pending starts as true and data is populated asynchronously. This avoids delaying page render at the cost of a loading state.Number of additional attempts to make after the first failure before the error is surfaced. Set to
3 to retry up to three extra times.Milliseconds to wait between retry attempts. Only applied when
retryCount is greater than 0.One or more Vue watch sources. Whenever any source changes,
useAsyncData re-runs the handler and updates data. This is the recommended way to re-fetch when a filter, page number, or other reactive value changes.Return Values
The resolved value returned by
handler. Starts as null (or the value returned by options.default() if provided) and is updated once the handler settles.true while a fetch is in progress, false otherwise. When lazy: true, starts as true until the initial fetch completes.The last error thrown by
handler, or null if the last fetch succeeded (or no fetch has run yet).A string enum that summarises the composite state:
| Value | Meaning |
|---|---|
'idle' | No fetch has started yet |
'pending' | A fetch is currently in-flight |
'success' | The last fetch completed successfully |
'error' | The last fetch threw an error |
Imperatively re-run the handler. Sets
status to 'pending' while running and resolves once the new result (or error) is stored. Useful for pull-to-refresh or polling patterns.Framework Utilities
setHydratedPayload
Populates the client-side hydration payload from the SSR-rendered page data. This is called automatically by the Nuxe runtime after the HTML is parsed — you do not need to call it manually in application code.
Example
Reactive key example
When the key is derived from reactive state,useAsyncData automatically re-fetches when the key changes:
Watching external sources
Usewatch to re-fetch when unrelated reactive state changes (e.g., a filter that affects the request body but not the key):