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

installation.md

67 lines1.5 KB

1---
2id: installation
3title: Installation
4---
5​
6You can install Vue Query via [NPM](https://npmjs.com).
7​
8### NPM
9​
10```bash
11npm i @tanstack/vue-query
12```
13​
14or
15​
16```bash
17pnpm add @tanstack/vue-query
18```
19​
20or
21​
22```bash
23yarn add @tanstack/vue-query
24```
25​
26or
27​
28```bash
29bun add @tanstack/vue-query
30```
31​
32> Wanna give it a spin before you download? Try out the [basic](./examples/basic) example!
33​
34Vue Query is compatible with Vue 2.x and 3.x
35​
36> If you are using Vue 2.6, make sure to also setup [@vue/composition-api](https://github.com/vuejs/composition-api)
37​
38### Vue Query Initialization
39​
40Before using Vue Query, you need to initialize it using `VueQueryPlugin`
41​
42```tsx
43import { VueQueryPlugin } from '@tanstack/vue-query'
44​
45app.use(VueQueryPlugin)
46```
47​
48### Use of Composition API with `<script setup>`
49​
50All examples in our documentation use [`<script setup>`](https://staging.vuejs.org/api/sfc-script-setup.html) syntax.
51​
52Vue 2 users can also use that syntax using [this plugin](https://github.com/antfu/unplugin-vue2-script-setup). Please check the plugin documentation for installation details.
53​
54If you are not a fan of `<script setup>` syntax, you can easily translate all the examples into normal Composition API syntax by moving the code under `setup()` function and returning the values used in the template.
55​
56```vue
57<script setup>
58import { useQuery } from '@tanstack/vue-query'
59​
60const { isPending, isFetching, isError, data, error } = useQuery({
61 queryKey: ['todos'],
62 queryFn: getTodos,
63})
64</script>
65​
66<template>...</template>
67```