refreshNuxtData()

Re-fetches data for one or more useAsyncData/useFetch keys.

Since Nuxt 3.0 Spec ↗

Syntax

await refreshNuxtData(keys?)

Parameters

NameTypeRequiredDescription
keys string | string[] No A key or array of keys to refresh. When omitted, all `useAsyncData`/`useFetch` calls are re-run.

Returns

Promise<void> — Resolves once the refresh completes.

Examples

<script setup lang="ts">
const { data } = await useFetch('/api/todos', { key: 'todos' })

async function addTodo() {
  await $fetch('/api/todos', { method: 'POST', body: { text: 'New' } })
  await refreshNuxtData('todos')
}
</script>
<script setup lang="ts">
// Refresh several caches at once after a mutation
await refreshNuxtData(['user', 'notifications'])
</script>

Notes

Triggers re-execution of the matching async data handlers and updates their reactive `data`. Prefer the `refresh()` returned by `useFetch`/`useAsyncData` for a single source; use `refreshNuxtData` to invalidate by key from elsewhere (e.g. after a global mutation).

See also