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

README.md

14 lines766 Bytes

1# TanStack Vue Query Default Query Function Example
2​
3Sets a default `queryFn` on the `QueryClient` that builds the request URL from the query key, so each query only passes a `queryKey`.
4​
5## How it works
6​
7- `src/main.ts` installs `VueQueryPlugin` with a `queryClientConfig` whose `defaultOptions.queries.queryFn` fetches `https://jsonplaceholder.typicode.com` plus `queryKey[0]`.
8- `src/PostList.vue` calls `useQuery` with only `queryKey: ['/posts']`, and shows a post in bold green when ``queryClient.getQueryData([`/posts/${post.id}`])`` returns data.
9- `src/PostDetail.vue` passes a getter to `useQuery` with ``queryKey: [`/posts/${props.postId}`]`` and `enabled: !!props.postId`, again without a `queryFn`.
10​
11To run this example:
12​
13- `npm install`
14- `npm run dev`