Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

README.md

15 lines956 Bytes

1# TanStack Vue Query Basic Example
2​
3A list of posts and a post detail view. Posts you have already opened are marked as visited from the query cache.
4​
5## How it works
6​
7- `src/services/posts/queries.ts` defines `postsQueries.list()` and `postsQueries.detail(id)`, `queryOptions` factories keyed by `['posts', 'list']` and `['posts', 'detail', id]`.
8- `src/PostList.vue` reads the list with `useQuery(postsQueries.list())` and marks a post as visited when `queryClient.getQueryData(postsQueries.detail(item.id).queryKey)` returns data.
9- `src/PostDetail.vue` passes a getter, `useQuery(() => postsQueries.detail(props.postId))`, so the query follows the `postId` prop. A cached post renders at once and shows "Background Updating..." while `isFetching` is `true`.
10- `src/main.ts` installs `VueQueryPlugin`, and `src/App.vue` switches between the list and the detail view and renders `VueQueryDevtools`.
11​
12To run this example:
13​
14- `npm install`
15- `npm run dev`