mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
feat(nuxt): filter support for clearNuxtData
(#7323)
This commit is contained in:
parent
eab4706614
commit
6b3a1a4256
@ -10,7 +10,7 @@ This method is useful if you want to invalidate the data fetching for another pa
|
||||
## Type
|
||||
|
||||
```ts
|
||||
clearNuxtData (keys?: string | string[]): void
|
||||
clearNuxtData (keys?: string | string[] | ((key: string) => boolean)): void
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
@ -254,9 +254,14 @@ export function refreshNuxtData (keys?: string | string[]): Promise<void> {
|
||||
return useNuxtApp().callHook('app:data:refresh', _keys)
|
||||
}
|
||||
|
||||
export function clearNuxtData (keys?: string | string[]): void {
|
||||
export function clearNuxtData (keys?: string | string[] | ((key: string) => boolean)): void {
|
||||
const nuxtApp = useNuxtApp()
|
||||
const _keys = keys ? Array.from(keys).filter(key => key && typeof key === 'string') : Object.keys(nuxtApp.payload.data)
|
||||
const _allKeys = Object.keys(nuxtApp.payload.data)
|
||||
const _keys: string[] = !keys
|
||||
? _allKeys
|
||||
: typeof keys === 'function'
|
||||
? _allKeys.filter(keys)
|
||||
: Array.isArray(keys) ? keys : [keys]
|
||||
|
||||
for (const key of _keys) {
|
||||
if (key in nuxtApp.payload.data) {
|
||||
|
Loading…
Reference in New Issue
Block a user