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-apiplugin
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
TheVueQueryPlugin accepts several configuration options:
Using a Custom QueryClient
Using QueryClientConfig
Alternatively, pass configuration directly:Enable DevTools
Enable Vue DevTools integration in development: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 yourtsconfig.json:
tsconfig.json
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 whenVueQueryPlugin 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:- Ensure
@vue/composition-apiis installed - Install it before VueQueryPlugin
- 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