Skip to main content

Installation

Get started with Vue Query in your Vue 2 or Vue 3 application.

Package Installation

Vue Version Requirements

Vue Query supports:
  • Vue 3.3+: Full support with Composition API
  • Vue 2.7: Built-in Composition API support
  • Vue 2.6: Requires @vue/composition-api plugin
Vue Query uses vue-demi to provide compatibility across Vue 2 and Vue 3, allowing you to use the same API regardless of your Vue version.

Vue 2.6 Setup

If you’re using Vue 2.6, you must install the Composition API plugin:

Plugin Configuration

Configuration Options

The VueQueryPlugin accepts several configuration options:

Using a Custom QueryClient

Using QueryClientConfig

Alternatively, pass configuration directly:

Enable DevTools

Enable Vue DevTools integration in development:
DevTools are automatically disabled in production builds. The enableDevtoolsV6Plugin option only works in development mode.

Custom Client Key

Use a custom injection key for multiple QueryClient instances:

Client Persistence

Persist and restore query cache using persisters:

TypeScript Configuration

For the best TypeScript experience, configure your tsconfig.json:
tsconfig.json
Vue Query has excellent TypeScript support with full type inference. See the TypeScript guide for advanced patterns.

Vite Configuration

If you’re using Vite, no additional configuration is needed. Vue Query works out of the box:
vite.config.ts

Webpack Configuration

For Webpack users with Vue 2, configure vue-demi aliasing:
webpack.config.js

Nuxt Configuration

For Nuxt applications, create a plugin file:

Troubleshooting

”No ‘queryClient’ found in Vue context”

This error occurs when VueQueryPlugin isn’t installed:

”vue-query hooks can only be used inside setup()”

Vue Query hooks must be called within:
  • Component setup() functions
  • <script setup> blocks
  • Active effect scopes created by effectScope()

Vue 2.6 Compatibility Issues

If you encounter errors with Vue 2.6:
  1. Ensure @vue/composition-api is installed
  2. Install it before VueQueryPlugin
  3. Use version 1.7.2 or higher of @vue/composition-api

Next Steps

Quick Start

Create your first query

TypeScript

Set up type safety

DevTools

Install and use DevTools

Overview

Learn core concepts