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

README.md

101 lines2.9 KB

1[![Vue Query logo](https://raw.githubusercontent.com/TanStack/query/main/packages/vue-query/media/vue-query.png)](https://github.com/TanStack/query/tree/main/packages/vue-query)
2​
3[![npm version](https://img.shields.io/npm/v/@tanstack/vue-query)](https://www.npmjs.com/package/@tanstack/vue-query)
4[![npm license](https://img.shields.io/npm/l/@tanstack/vue-query)](https://github.com/TanStack/query/blob/main/LICENSE)
5[![bundle size](https://img.shields.io/bundlephobia/minzip/@tanstack/vue-query)](https://bundlephobia.com/package/@tanstack/vue-query)
6[![npm](https://img.shields.io/npm/dm/@tanstack/vue-query)](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- [![npm bundle size](https://img.shields.io/bundlephobia/minzip/@tanstack/vue-query)](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 ```