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