Skip to content

Commit

Permalink
docs: add example for clear
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 17, 2024
1 parent 1cae15a commit 24217a9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/1.getting-started/6.data-fetching.md
Expand Up @@ -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).
::

#### 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

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.
Expand Down

0 comments on commit 24217a9

Please sign in to comment.