examples/vue/pagination-nuxt4
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Vue Query Pagination Example (Nuxt 4)#
Paginated projects with placeholderData: keepPreviousData, so the current page stays visible while the next one loads. The next page is prefetched.
Built with Nuxt 4.
How it works#
app/services/projects/queries.tsdefinesprojectsQueries.list(page), aqueryOptionsfactory keyed by['projects', 'list', page]with a 5-secondstaleTime.app/app.vuepasses a getter touseQuerywithplaceholderData: keepPreviousData. While the next page loads,datastill holds the previous page andisPlaceholderDataistrue, which disables the "Next Page" button.- A
watchEffectinapp/app.vuefetches the next page ahead of time withqueryClient.query(projectsQueries.list(page.value + 1))when the current page hashasMore: true. 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/projects.tsis a Nitro handler that returns 10 projects per page after a 1-second delay, withhasMore: page < 9.
To run this example:
npm installnpm run dev