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

VueQueryPlugin.md

64 lines1.4 KB

1---
2id: VueQueryPlugin
3title: VueQueryPlugin
4---
5​
6```ts
7const VueQueryPlugin: object;
8```
9​
10Defined in: [packages/vue-query/src/vueQueryPlugin.ts:75](https://github.com/TanStack/query/blob/main/packages/vue-query/src/vueQueryPlugin.ts#L75)
11​
12Installs a `QueryClient` on the Vue app, making it available to every descendant component through
13`useQueryClient` β€” the Vue equivalent of React's `QueryClientProvider`, but wired up as an app-level plugin
14instead of a wrapping component.
15​
16## Type Declaration
17​
18### install
19​
20```ts
21install: (app: any, options: VueQueryPluginOptions) => void;
22```
23​
24#### Parameters
25​
26##### app
27​
28`any`
29​
30##### options?
31​
32[`VueQueryPluginOptions`](../type-aliases/VueQueryPluginOptions.md) = `{}`
33​
34#### Returns
35​
36`void`
37​
38## Examples
39​
40```ts
41import { createApp } from 'vue'
42import { VueQueryPlugin } from '@tanstack/vue-query'
43​
44const app = createApp(App)
45app.use(VueQueryPlugin)
46```
47​
48Pass a `queryClient` you constructed yourself β€” useful for SSR, where you need a fresh `QueryClient` per
49request, or when the same instance also needs to be used outside of Vue components:
50```ts
51import { QueryClient, VueQueryPlugin } from '@tanstack/vue-query'
52​
53const queryClient = new QueryClient()
54app.use(VueQueryPlugin, { queryClient })
55```
56​
57Or pass `queryClientConfig` to let the plugin construct the `QueryClient` for you, with your own defaults:
58```ts
59app.use(VueQueryPlugin, {
60 queryClientConfig: {
61 defaultOptions: { queries: { staleTime: 5 * 1000 } },
62 },
63})
64```