Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update docs and simplify api
  • Loading branch information
pi0 committed Sep 7, 2022
commit 5d2f5cf27cdd0e285028f476686c551e2181c6ab
20 changes: 10 additions & 10 deletions docs/content/2.guide/2.features/5.data-fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,7 @@ This method is useful if you want to refresh all the data fetching for a current
::ReadMore{link="/api/utils/refresh-nuxt-data"}
::

### `clearNuxtData`

Delete cache of `useAsyncData`, `useLazyAsyncData`, `useFetch` and `useLazyFetch`.

This method is useful if you want to invalidate the data fetching for another page.

::ReadMore{link="/api/utils/clear-nuxt-cache"}
::

### Example
#### Example

```vue
<template>
Expand All @@ -182,6 +173,15 @@ const refresh = () => refreshNuxtData('count')
</script>
```

### `clearNuxtData`

Delete cached data, error status and pending promises of `useAsyncData` and `useFetch`.

This method is useful if you want to invalidate the data fetching for another page.

::ReadMore{link="/api/utils/clear-nuxt-data"}
::

## Options API support

Nuxt 3 provides a way to perform `asyncData` fetching within the Options API. You must wrap your component definition within `defineNuxtComponent` for this to work.
Expand Down
11 changes: 8 additions & 3 deletions docs/content/3.api/3.utils/clear-nuxt-data.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# `clearNuxtData`

Clears cache of `useAsyncData`, `useLazyAsyncData`, `useFetch` and `useLazyFetch`.
::StabilityEdge
::

Delete cached data, error status and pending promises of `useAsyncData` and `useFetch`.

This method is useful if you want to invalidate the data fetching for another page.

## Type

```ts
clearNuxtData ({ keys }: {keys: string | string[]})
clearNuxtData (keys?: string | string[])
```

Available options:
## Parameters

* `keys`: Provides an array of keys that are used in `useAsyncData` to delete cached data.
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/composables/asyncData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export function refreshNuxtData (keys?: string | string[]): Promise<void> {
return useNuxtApp().callHook('app:data:refresh', _keys)
}

export function clearNuxtData ({ keys }: {keys: string | string[]}): void {
export function clearNuxtData (keys?: string | string[]): void {
const _keys = keys ? Array.isArray(keys) ? keys : [keys] : undefined
if (_keys === undefined) {
return
Expand Down