examples/vue/basic
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Vue Query Basic Example#
A list of posts and a post detail view. Posts you have already opened are marked as visited from the query cache.
How it works#
src/services/posts/queries.tsdefinespostsQueries.list()andpostsQueries.detail(id),queryOptionsfactories keyed by['posts', 'list']and['posts', 'detail', id].src/PostList.vuereads the list withuseQuery(postsQueries.list())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. A cached post renders at once and shows "Background Updating..." whileisFetchingistrue.src/main.tsinstallsVueQueryPlugin, andsrc/App.vueswitches between the list and the detail view and rendersVueQueryDevtools.
To run this example:
npm installnpm run dev