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/v4/docs/adapters/vue-query
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 > If you are using Vue 2.6, make sure to also setup [@vue/composition-api](https://github.com/vuejs/composition-api)
54β
552. Initialize **Vue Query** via **VueQueryPlugin**
56β
57 ```tsx
58 import { createApp } from 'vue'
59 import { VueQueryPlugin } from '@tanstack/vue-query'
60β
61 import App from './App.vue'
62β
63 createApp(App).use(VueQueryPlugin).mount('#app')
64 ```
65β
663. Use query
67β
68 ```tsx
69 import { defineComponent } from 'vue'
70 import { useQuery } from '@tanstack/vue-query'
71β
72 export default defineComponent({
73 name: 'MyComponent',
74 setup() {
75 const query = useQuery({ queryKey: ['todos'], queryFn: getTodos })
76β
77 return {
78 query,
79 }
80 },
81 })
82 ```
83β
844. If you need to update options on your query dynamically, make sure to pass them as reactive variables
85β
86 ```tsx
87 const id = ref(1)
88 const enabled = ref(false)
89β
90 const query = useQuery({
91 queryKey: ['todos', id],
92 queryFn: () => getTodos(id),
93 enabled,
94 })
95 ```