examples/vue/auto-refetching-nuxt4
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Vue Query Auto Refetching Example (Nuxt 4)#
A todo list that polls the server with refetchInterval. Adding a todo or clearing the list invalidates the query.
Built with Nuxt 4.
How it works#
app/services/todos/queries.tsdefinestodosQueries.list()withqueryOptions, andtodosMutations.create()andtodosMutations.deleteAll()withmutationOptions.app/services/todos/api.tscalls the server with$fetch.app/app.vuepasses a getter touseQuerythat addsrefetchInterval: intervalMs.value, so changing the interval input changes the polling rate. A dot next to the input lights up whileisFetchingistrue.- In
app/app.vue, adding a todo and clearing the list useuseMutation, and both invalidatetodosQueries.all()on success. app/plugins/vue-query.tsis a Nuxt plugin that creates aQueryClientand installsVueQueryPlugin. On the server it storesdehydrate(queryClient)inuseState('vue-query')onapp:rendered, and on the client it callshydratewith that state onapp:created.server/api/data.tsis a Nitro handler that keeps the list in memory, adds an item for?add=or clears it for?clear=, and responds after 100 ms.
To run this example:
npm installnpm run dev