Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24217a9

Browse files
committed
docs: add example for clear
1 parent 1cae15a commit 24217a9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/1.getting-started/6.data-fetching.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,21 @@ The `execute` function is an alias for `refresh` that works in exactly the same
295295
To globally refetch or invalidate cached data, see [`clearNuxtData`](/docs/api/utils/clear-nuxt-data) and [`refreshNuxtData`](/docs/api/utils/refresh-nuxt-data).
296296
::
297297

298+
#### Clear
299+
300+
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.
301+
302+
```vue twoslash
303+
<script setup lang="ts">
304+
const { data, clear } = await useFetch('/api/users')
305+
306+
const route = useRoute()
307+
watch(() => route.path, (path) => {
308+
if (path === '/') clear()
309+
})
310+
</script>
311+
```
312+
298313
#### Watch
299314

300315
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.

0 commit comments

Comments
 (0)