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