File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
examples/nuxt3-simple/plugins Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 1+ import type { DehydratedState , VueQueryPluginOptions } from 'vue-query'
12import {
23 VueQueryPlugin ,
3- VueQueryPluginOptions ,
44 QueryClient ,
55 hydrate ,
66 dehydrate ,
77} from "vue-query" ;
8+ // Nuxt 3 app aliases
9+ import { useState } from '#app'
810
911export default ( nuxt ) => {
1012 // Modify your Vue Query global settings here
@@ -14,18 +16,19 @@ export default (nuxt) => {
1416 const options : VueQueryPluginOptions = { queryClient } ;
1517
1618 nuxt . vueApp . use ( VueQueryPlugin , options ) ;
19+ const vueQueryClient = useState < DehydratedState | null > ( 'vue-query' )
1720
1821 // @ts -expect-error Nuxt process variable
1922 if ( process . server ) {
20- nuxt . hooks . hook ( " app:rendered" , ( ) => {
21- nuxt . nuxtState [ "vue-query" ] = dehydrate ( queryClient ) ;
22- } ) ;
23+ nuxt . hooks . hook ( ' app:rendered' , ( ) => {
24+ vueQueryClient . value = dehydrate ( queryClient )
25+ } )
2326 }
2427
2528 // @ts -expect-error Nuxt process variable
2629 if ( process . client ) {
27- nuxt . hooks . hook ( " app:created" , ( ) => {
28- hydrate ( queryClient , nuxt . nuxtState [ "vue-query" ] ) ;
29- } ) ;
30+ nuxt . hooks . hook ( ' app:created' , ( ) => {
31+ hydrate ( queryClient , vueQueryClient . value )
32+ } )
3033 }
3134} ;
You can’t perform that action at this time.
0 commit comments