Skip to main content

Vue Query Overview

Vue Query provides hooks for fetching, caching, and updating asynchronous data in Vue applications. It’s built on top of TanStack Query’s framework-agnostic core and provides a Vue-specific API with full support for Vue’s reactivity system.

Key Features

Vue Query brings powerful data management capabilities to your Vue applications:
  • Transport/Protocol Agnostic: Works with REST, GraphQL, promises, or any async data source
  • Automatic Caching: Smart caching with configurable stale-while-revalidate strategies
  • Auto Refetching: Refetch on window focus, network reconnect, polling, or custom intervals
  • Parallel & Dependent Queries: Execute multiple queries simultaneously or chain them together
  • Mutations with Optimistic Updates: Update data with automatic query invalidation and rollback
  • Infinite Scroll Support: Built-in support for paginated and cursor-based queries
  • Request Cancellation: Automatic cancellation of outdated requests
  • SSR Support: Server-side rendering with hydration/dehydration
  • Vue DevTools Integration: Debug your queries with the official Vue DevTools plugin
  • Vue 2 & 3 Support: Works with Vue 2.6+, 2.7, and Vue 3 via vue-demi

Vue Reactivity Integration

Vue Query is designed to work seamlessly with Vue’s reactivity system:

Core Concepts

Queries

Queries are declarative dependencies on asynchronous data sources. Use useQuery to fetch and cache data:

Mutations

Mutations are used to create, update, or delete data:

Query Invalidation

Invalidate queries to mark them as stale and trigger refetching:

Architecture

Comparison with Other Solutions

vs Pinia/Vuex

Vue Query is specifically designed for asynchronous server state, while Pinia and Vuex excel at client-side state management. They solve different problems:
Use Vue Query for server data and Pinia for client state. They complement each other perfectly!

vs Apollo Client

Vue Query is protocol-agnostic while Apollo is GraphQL-specific:
  • Vue Query: Works with any async data source (REST, GraphQL, etc.)
  • Apollo Client: Deeply integrated with GraphQL, includes code generation
If you’re exclusively using GraphQL, Apollo provides GraphQL-specific features like fragments and schema integration. For REST or mixed APIs, Vue Query is more flexible.

Vue 2 Support

Vue Query supports Vue 2.6+ through the vue-demi compatibility layer:
For Vue 2.6, you must install @vue/composition-api:
Vue 2.7 includes the Composition API, so no additional package is needed.

Framework Features

Vue Query leverages Vue-specific features:

Shallow Refs

Improve performance for large datasets with shallow reactivity:

Scope Disposal

Queries automatically clean up when the component unmounts:
Vue Query automatically handles cleanup using onScopeDispose, so you rarely need to manage it manually.

TypeScript Support

Vue Query is written in TypeScript and provides full type safety:
See the TypeScript guide for advanced type patterns.

Next Steps

Installation

Install Vue Query and set up the plugin

Quick Start

Build your first query in minutes

TypeScript

Learn about type safety and inference

DevTools

Debug queries with Vue DevTools integration