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

installation.md

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