mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 09:25:54 +00:00
feat(nuxt): add private option to useAsyncData (#29064)
This commit is contained in:
parent
f71cc9ddd1
commit
bae3008728
@ -65,6 +65,7 @@ const { data: posts } = await useAsyncData(
|
||||
- `handler`: an asynchronous function that must return a truthy value (for example, it should not be `undefined` or `null`) or the request may be duplicated on the client side
|
||||
- `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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user