From 698f3b1b4a93ced58ed9c1d1066fc57a652c452b Mon Sep 17 00:00:00 2001 From: Damian Osipiuk Date: Sun, 1 Sep 2024 22:54:07 +0200 Subject: [PATCH 1/2] docs: update SSR guide for nuxt2 --- docs/framework/vue/guides/ssr.md | 35 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/docs/framework/vue/guides/ssr.md b/docs/framework/vue/guides/ssr.md index d0933289125..b2be22cadcd 100644 --- a/docs/framework/vue/guides/ssr.md +++ b/docs/framework/vue/guides/ssr.md @@ -82,11 +82,14 @@ export default (context) => { const queryClient = new QueryClient({ defaultOptions: { queries: { staleTime: 5000 } }, }) - const options = { queryClient } - Vue.use(VueQueryPlugin, options) + if (process.server) { + context.ssrContext.VueQuery = queryClient + } if (process.client) { + Vue.use(VueQueryPlugin, { queryClient }) + if (context.nuxtState && context.nuxtState.vueQueryState) { hydrate(queryClient, context.nuxtState.vueQueryState) } @@ -100,7 +103,7 @@ Add this plugin to your `nuxt.config.js` module.exports = { ... plugins: ['~/plugins/vue-query.js'], -}; +} ``` Now you are ready to prefetch some data in your pages with `onServerPrefetch`. @@ -110,7 +113,7 @@ Now you are ready to prefetch some data in your pages with `onServerPrefetch`. - Prefetch all the queries that you need with `queryClient.prefetchQuery` or `suspense` - Dehydrate `queryClient` to the `nuxtContext` -```js +```vue // pages/todos.vue