mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-01 18:07:22 +00:00
docs: add example for clear
This commit is contained in:
parent
1cae15a3a4
commit
24217a9920
@ -295,6 +295,21 @@ The `execute` function is an alias for `refresh` that works in exactly the same
|
|||||||
To globally refetch or invalidate cached data, see [`clearNuxtData`](/docs/api/utils/clear-nuxt-data) and [`refreshNuxtData`](/docs/api/utils/refresh-nuxt-data).
|
To globally refetch or invalidate cached data, see [`clearNuxtData`](/docs/api/utils/clear-nuxt-data) and [`refreshNuxtData`](/docs/api/utils/refresh-nuxt-data).
|
||||||
::
|
::
|
||||||
|
|
||||||
|
#### Clear
|
||||||
|
|
||||||
|
If you want to clear the data provided, for whatever reason, without needing to know the specific key to pass to `clearNuxtData`, you can use the `clear` function provided by the composables.
|
||||||
|
|
||||||
|
```vue twoslash
|
||||||
|
<script setup lang="ts">
|
||||||
|
const { data, clear } = await useFetch('/api/users')
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
watch(() => route.path, (path) => {
|
||||||
|
if (path === '/') clear()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
#### Watch
|
#### Watch
|
||||||
|
|
||||||
To re-run your fetching function each time other reactive values in your application change, use the `watch` option. You can use it for one or multiple _watchable_ elements.
|
To re-run your fetching function each time other reactive values in your application change, use the `watch` option. You can use it for one or multiple _watchable_ elements.
|
||||||
|
Loading…
Reference in New Issue
Block a user