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

installation.md

55 lines1.5 KB

1---
2id: installation
3title: Installation
4---
5​
6You can install Vue Query via [NPM](https://npmjs.com).
7​
8> v5 is currently in alpha.
9​
10### NPM
11​
12```bash
13$ npm i @tanstack/vue-query@alpha
14# or
15$ pnpm add @tanstack/vue-query@alpha
16# or
17$ yarn add @tanstack/vue-query@alpha
18```
19​
20> Wanna give it a spin before you download? Try out the [basic](../examples/vue/basic) example!
21​
22Vue Query is compatible with Vue 2.x and 3.x
23​
24> If you are using Vue 2.6, make sure to also setup [@vue/composition-api](https://github.com/vuejs/composition-api)
25​
26### Vue Query Initialization
27​
28Before using Vue Query, you need to initialize it using `VueQueryPlugin`
29​
30```tsx
31import { VueQueryPlugin } from "@tanstack/vue-query";
32​
33app.use(VueQueryPlugin)
34```
35​
36### Use of Composition API with `<script setup>`
37​
38All examples in our documentation use [`<script setup>`](https://staging.vuejs.org/api/sfc-script-setup.html) syntax.
39​
40Vue 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.
41​
42If 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.
43​
44```vue
45<script setup>
46import { useQuery } from "@tanstack/vue-query";
47​
48const { isPending, isFetching, isError, data, error } = useQuery({
49 queryKey: ['todos'],
50 queryFn: getTodos,
51})
52</script>
53​
54<template>...</template>
55```