mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
docs: add another example for useAsyncData
(#19225)
This commit is contained in:
parent
97ae4e23f9
commit
801aba830e
@ -80,6 +80,24 @@ const { data, pending, error, refresh } = await useAsyncData(
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Example with watching params change
|
||||||
|
|
||||||
|
The built-in `watch` option allows automatically rerunning the fetcher function when any changes are detected.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const page = ref(1)
|
||||||
|
const { data: posts } = await useAsyncData(
|
||||||
|
'posts',
|
||||||
|
() => $fetch('https://fakeApi.com/posts', {
|
||||||
|
params: {
|
||||||
|
page: page.value
|
||||||
|
}
|
||||||
|
}), {
|
||||||
|
watch: [page]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
::alert{type=warning}
|
::alert{type=warning}
|
||||||
`useAsyncData` is a reserved function name transformed by the compiler, so you should not name your own function `useAsyncData`.
|
`useAsyncData` is a reserved function name transformed by the compiler, so you should not name your own function `useAsyncData`.
|
||||||
::
|
::
|
||||||
|
Loading…
Reference in New Issue
Block a user