examples/vue/2.7-basic
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Vue Query 2.7 Basic Example#
The basic posts example on Vue 2.7.
How it works#
src/services/posts/queries.tsdefinespostsQueries.list()andpostsQueries.detail(id),queryOptionsfactories keyed by['posts', 'list']and['posts', 'detail', id].src/Posts.vuereads the list withuseQuery(postsQueries.list())and marks a post as visited whenqueryClient.getQueryData(postsQueries.detail(item.id).queryKey)returns data.src/Post.vuepasses a getter,useQuery(() => postsQueries.detail(props.postId)), so the query follows thepostIdprop. A cached post renders at once and shows "Background Updating..." whileisFetchingistrue.src/main.tsinstallsVueQueryPluginwithVue.useand mounts the app withnew Vue, using Vue 2.7's built-in Composition API.
To run this example:
npm installnpm run dev