examples/vue/persister
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Vue Query Persister Example#
Persists each query on its own with experimental_createQueryPersister: the post list to localStorage and each post to IndexedDB.
How it works#
src/services/posts/queries.tscreates two persisters withexperimental_createQueryPersister: one onlocalStorageand one on IndexedDB throughidb-keyval.- In
src/services/posts/queries.ts,postsQueries.list()passespostsPersister.persisterFn(thelocalStorageone) aspersisterwith a 5-secondstaleTime, andpostsQueries.detail(id)passespostPersister.persisterFn(the IndexedDB one). src/PostList.vuereads the list withuseQuery(postsQueries.list()), shows "Refetching..." whileisRefetchingistrue, and marks a post as visited whenqueryClient.getQueryData(postsQueries.detail(item.id).queryKey)returns data.src/PostDetail.vuepasses a getter,useQuery(() => postsQueries.detail(props.postId)), so the query follows thepostIdprop.src/main.tsinstallsVueQueryPluginwith a defaultgcTimeof 24 hours, andsrc/services/posts/api.tsdelays the list response by 1 second.
To run this example:
npm installnpm run dev