Quick Start
This guide will walk you through the basics of Vue Query, from installation to making your first queries and mutations.Prerequisites
Before starting, make sure you have:- Vue 2.6+ or Vue 3.3+
- Node.js 16+
- Basic familiarity with Vue Composition API
Installation
Understanding Queries
Query Keys
Query keys uniquely identify queries in the cache. They can be strings or arrays:When any value in the query key changes, Vue Query automatically refetches the data.
Query Functions
Query functions must return a Promise. They receive a context object with useful information:Query Results
useQuery returns reactive refs with query state:
Working with Reactive Data
Vue Query embraces Vue’s reactivity system. Options can be refs, reactive objects, or computed values:UserProfile.vue
Mutations
UseuseMutation to create, update, or delete data:
CreateTodo.vue
Mutation with Optimistic Updates
Update the UI immediately while the mutation is in progress:Dependent Queries
Enable queries only when dependencies are ready:UserPosts.vue
Parallel Queries
Execute multiple queries simultaneously:useQueries for dynamic parallel queries:
Infinite Queries
Implement infinite scroll and pagination:InfiniteList.vue
Query Options
Extract and reuse query configurations withqueryOptions:
queries/todos.ts
Component.vue
Error Handling
Handle errors at the query level or globally:Caching Behavior
Control how long data stays fresh and in cache:- staleTime: How long data is considered fresh (default: 0)
- gcTime (formerly cacheTime): How long unused data stays in cache (default: 5 minutes)
Next Steps
TypeScript Guide
Learn about type safety and inference
DevTools
Debug queries with Vue DevTools
API Reference
Explore the complete API
Examples
View real-world examples