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

VueQueryPlugin.md

66 lines1.5 KB

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