mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +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
|
- `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`:
|
- `options`:
|
||||||
- `server`: whether to fetch the data on the server (defaults to `true`)
|
- `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`)
|
- `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`)
|
- `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
|
- `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
|
* @default true
|
||||||
*/
|
*/
|
||||||
server?: boolean
|
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
|
* Whether to resolve the async function after loading the route, instead of blocking client-side navigation
|
||||||
* @default false
|
* @default false
|
||||||
@ -230,7 +235,8 @@ export function useAsyncData<
|
|||||||
const getDefaultCachedData = () => nuxtApp.isHydrating ? nuxtApp.payload.data[key] : nuxtApp.static.data[key]
|
const getDefaultCachedData = () => nuxtApp.isHydrating ? nuxtApp.payload.data[key] : nuxtApp.static.data[key]
|
||||||
|
|
||||||
// Apply defaults
|
// 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.default = options.default ?? (getDefault as () => DefaultT)
|
||||||
options.getCachedData = options.getCachedData ?? getDefaultCachedData
|
options.getCachedData = options.getCachedData ?? getDefaultCachedData
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user