This commit is contained in:
Connor Pearson 2025-02-14 20:07:48 +01:00 committed by GitHub
commit 2755818ff5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -68,6 +68,7 @@ The `handler` function should be **side-effect free** to ensure predictable beha
::
- `options`:
- `server`: whether to fetch the data on the server (defaults to `true`)
- `private`: when true, `server` will default to `false` on cached pages and `true` on uncached pages (defaults to `false`)
- `lazy`: whether to resolve the async function after loading the route, instead of blocking client-side navigation (defaults to `false`)
- `immediate`: when set to `false`, will prevent the request from firing immediately. (defaults to `true`)
- `default`: a factory function to set the default value of the `data`, before the async function resolves - useful with the `lazy: true` or `immediate: false` option

View File

@ -49,6 +49,11 @@ export interface AsyncDataOptions<
* @default true
*/
server?: boolean
/**
* When true, `server` will default to false on cached pages and true on uncached pages
* @default false
*/
private?: false
/**
* Whether to resolve the async function after loading the route, instead of blocking client-side navigation
* @default false
@ -230,7 +235,8 @@ export function useAsyncData<
const getDefaultCachedData = () => nuxtApp.isHydrating ? nuxtApp.payload.data[key] : nuxtApp.static.data[key]
// Apply defaults
options.server = options.server ?? true
const cachedRoute = !!nuxtApp.ssrContext?.event?.context.cache
options.server = options.server ?? (options.private ? !cachedRoute : true)
options.default = options.default ?? (getDefault as () => DefaultT)
options.getCachedData = options.getCachedData ?? getDefaultCachedData