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.
useFetch is a convenience wrapper around useAsyncData and Nuxe’s $fetch client. It accepts a URL (or URL getter) and an options object that combines standard fetch configuration with useAsyncData’s SSR and retry options. Any reactive value passed to method, baseURL, query, params, body, or headers is automatically unwrapped before every request, and changes to those values (or the URL getter) trigger a transparent re-fetch.
useFetch tracks the HTTP response status code in a separate statusCode ref, which is serialized into the SSR payload alongside data and restored on the client — giving you accurate status information even after hydration.Signature
Parameters
The URL to fetch. When a getter function is provided,
useFetch watches its return value and re-fetches automatically on every change. A key must be supplied in options whenever a function is used (see below).Combines
UseAsyncDataOptions with standard ofetch FetchOptions. All fields are optional unless noted.Cache key used for SSR deduplication and hydration. Required when
url is a function. If omitted for a string URL, the URL string itself is used as the key.HTTP method (
'GET', 'POST', 'PUT', 'DELETE', etc.). Accepts a plain string or a reactive Ref. Defaults to 'GET'.Base URL prepended to the request URL for relative paths. Accepts a plain string or a reactive
Ref. On the server, defaults to the app’s configured base URL or http://localhost:3000.URL query parameters, serialized and appended to the URL. Refs and nested Refs are deeply unwrapped before the request is sent. Alias:
params.Alias for
query. If both are provided, they are merged.Request body. Objects are automatically JSON-serialized. Accepts a reactive
Ref — the unwrapped value is sent on every request.Additional request headers. Merged with any headers forwarded from the SSR request context.
Called on both network errors (no response) and HTTP error responses (4xx / 5xx). Receives a
UseFetchError that extends Error with optional status, statusText, and response fields.Response interceptor called after every successful response, before the data is stored. Receives the full
ofetch FetchContext object including response.Factory for the initial
data value before the first response arrives. Inherited from UseAsyncDataOptions.Set to
false to skip the handler on the server and fetch only on the client.Run the fetch after mount rather than blocking navigation.
Number of retry attempts after a failure.
Delay in milliseconds between retries.
Additional watch sources that trigger a re-fetch when they change, on top of the built-in URL and options watching.
UseFetchError
The error shape passed to onError and surfaced in the error ref for HTTP-level failures.
The HTTP status code from the error response (e.g.
404, 500). undefined for network-level errors where no response was received.The HTTP status text from the error response (e.g.
"Not Found"). undefined for network-level errors.The full
Response object when an HTTP error response was received. undefined for network-level errors.Return Values
UseFetchReturn<T> extends UseAsyncDataReturn<T> with one additional field:
The HTTP status code from the most recent response (
200, 404, 500, etc.). null before any response is received or when the request fails at the network level without a response.The parsed JSON response body.
true while a request is in-flight.The last error, or
null on success.Composite status string. See
useAsyncData status values.Imperatively re-run the fetch.
Examples
Basic GET request
Reactive query parameters
When a reactive value changes,useFetch re-fetches automatically: