Skip to main content

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
Using reactive options is more efficient than options getter functions. Vue Query tracks dependencies automatically.

Mutations

Use useMutation 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:
Or use useQueries for dynamic parallel queries:

Infinite Queries

Implement infinite scroll and pagination:
InfiniteList.vue

Query Options

Extract and reuse query configurations with queryOptions:
queries/todos.ts
Component.vue
queryOptions provides perfect TypeScript inference and makes query configurations reusable across queries, prefetching, and server-side code.

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