mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
docs: add documentation on getCachedData
option (#24697)
This commit is contained in:
parent
8ccafb182d
commit
628dc716b5
@ -61,6 +61,7 @@ const { data: posts } = await useAsyncData(
|
||||
- `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
|
||||
- `transform`: a function that can be used to alter `handler` function result after resolving
|
||||
- `getCachedData`: Provide a function which returns cached data. A _null_ or _undefined_ return value will trigger a fetch. By default, this is: `key => nuxt.isHydrating ? nuxt.payload.data[key] : nuxt.static.data[key]`, which only caches data when `payloadExtraction` is enabled.
|
||||
- `pick`: only pick specified keys in this array from the `handler` function result
|
||||
- `watch`: watch reactive sources to auto-refresh
|
||||
- `deep`: return data in a deep ref object (it is `true` by default). It can be set to `false` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.
|
||||
@ -76,6 +77,10 @@ Under the hood, `lazy: false` uses `<Suspense>` to block the loading of the rout
|
||||
You can use `useLazyAsyncData` to have the same behavior as `lazy: true` with `useAsyncData`.
|
||||
::
|
||||
|
||||
::callout{icon="i-simple-icons-youtube" color="gray" to="https://www.youtube.com/watch?v=aQPR0xn-MMk" target="_blank"}
|
||||
Learn how to use `transform` and `getCachedData` to avoid superfluous calls to an API and cache data for visitors on the client.
|
||||
::
|
||||
|
||||
## Return Values
|
||||
|
||||
- `data`: the result of the asynchronous function that is passed in.
|
||||
|
@ -93,6 +93,7 @@ All fetch options can be given a `computed` or `ref` value. These will be watche
|
||||
- `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
|
||||
- `transform`: a function that can be used to alter `handler` function result after resolving
|
||||
- `getCachedData`: Provide a function which returns cached data. A _null_ or _undefined_ return value will trigger a fetch. By default, this is: `key => nuxt.isHydrating ? nuxt.payload.data[key] : nuxt.static.data[key]`, which only caches data when `payloadExtraction` is enabled.
|
||||
- `pick`: only pick specified keys in this array from the `handler` function result
|
||||
- `watch`: watch an array of reactive sources and auto-refresh the fetch result when they change. Fetch options and URL are watched by default. You can completely ignore reactive sources by using `watch: false`. Together with `immediate: false`, this allows for a fully-manual `useFetch`.
|
||||
- `deep`: return data in a deep ref object (it is `true` by default). It can be set to `false` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.
|
||||
@ -104,6 +105,10 @@ All fetch options can be given a `computed` or `ref` value. These will be watche
|
||||
If you provide a function or ref as the `url` parameter, or if you provide functions as arguments to the `options` parameter, then the `useFetch` call will not match other `useFetch` calls elsewhere in your codebase, even if the options seem to be identical. If you wish to force a match, you may provide your own key in `options`.
|
||||
::
|
||||
|
||||
::callout{icon="i-simple-icons-youtube" color="gray" to="https://www.youtube.com/watch?v=aQPR0xn-MMk" target="_blank"}
|
||||
Learn how to use `transform` and `getCachedData` to avoid superfluous calls to an API and cache data for visitors on the client.
|
||||
::
|
||||
|
||||
## Return Values
|
||||
|
||||
- `data`: the result of the asynchronous function that is passed in.
|
||||
|
Loading…
Reference in New Issue
Block a user