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

README.md

95 lines2.8 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/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- [![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 > 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 ```