Open History to see the last commit
1[](https://github.com/TanStack/query/tree/main/packages/vue-query)
2β
3[](https://www.npmjs.com/package/@tanstack/vue-query)
4[](https://github.com/TanStack/query/blob/main/LICENSE)
5[](https://bundlephobia.com/package/@tanstack/vue-query)
6[](https://www.npmjs.com/package/@tanstack/vue-query)
7β
8# Vue Query
9β
10Hooks for fetching, caching and updating asynchronous data in Vue.
11β
12Support for Vue 2.x via [vue-demi](https://github.com/vueuse/vue-demi)
13β
14# Documentation
15β
16Visit https://tanstack.com/query/latest/docs/vue/overview
17β
18# Quick Features
19β
20- Transport/protocol/backend agnostic data fetching (REST, GraphQL, promises, whatever!)
21- Auto Caching + Refetching (stale-while-revalidate, Window Refocus, Polling/Realtime)
22- Parallel + Dependent Queries
23- Mutations + Reactive Query Refetching
24- Multi-layer Cache + Automatic Garbage Collection
25- Paginated + Cursor-based Queries
26- Load-More + Infinite Scroll Queries w/ Scroll Recovery
27- Request Cancellation
28- (experimental) [Suspense](https://v3.vuejs.org/guide/migration/suspense.html#introduction) + Fetch-As-You-Render Query Prefetching
29- (experimental) SSR support
30- Dedicated Devtools
31- [](https://bundlephobia.com/package/@tanstack/vue-query) (depending on features imported)
32β
33# Quick Start
34β
351. Install `vue-query`
36β
37 ```bash
38 $ npm i @tanstack/vue-query
39 ```
40β
41 or
42β
43 ```bash
44 $ pnpm add @tanstack/vue-query
45 ```
46β
47 or
48β
49 ```bash
50 $ yarn add @tanstack/vue-query
51 ```
52β
53 or
54β
55 ```bash
56 $ bun add @tanstack/vue-query
57 ```
58β
59 > If you are using Vue 2.6, make sure to also setup [@vue/composition-api](https://github.com/vuejs/composition-api)
60β
612. Initialize **Vue Query** via **VueQueryPlugin**
62β
63 ```tsx
64 import { createApp } from 'vue'
65 import { VueQueryPlugin } from '@tanstack/vue-query'
66β
67 import App from './App.vue'
68β
69 createApp(App).use(VueQueryPlugin).mount('#app')
70 ```
71β
723. Use query
73β
74 ```tsx
75 import { defineComponent } from 'vue'
76 import { useQuery } from '@tanstack/vue-query'
77β
78 export default defineComponent({
79 name: 'MyComponent',
80 setup() {
81 const query = useQuery({ queryKey: ['todos'], queryFn: getTodos })
82β
83 return {
84 query,
85 }
86 },
87 })
88 ```
89β
904. If you need to update options on your query dynamically, make sure to pass them as reactive variables
91β
92 ```tsx
93 const id = ref(1)
94 const enabled = ref(false)
95β
96 const query = useQuery({
97 queryKey: ['todos', id],
98 queryFn: () => getTodos(id),
99 enabled,
100 })
101 ```