Skip to main content
TanStack Query for Vue provides composables for fetching, caching, and updating asynchronous data in your Vue applications. It supports both Vue 2 (with @vue/composition-api) and Vue 3.

Installation

For Vue 2, you also need to install @vue/composition-api:

Setup

Install the Vue Query plugin in your app:

Plugin Options

Core Composables

useQuery

Fetch and cache data with the useQuery composable:

Reactive Query Keys

Vue Query fully supports Vue’s reactivity system. Use ref or computed for dynamic queries:
When using refs in query options, Vue Query automatically unwraps them. You can pass todoId directly instead of todoId.value.

useMutation

Perform side effects with mutations:

useInfiniteQuery

Implement infinite scrolling:

Reactivity Patterns

MaybeRef and MaybeRefDeep

Vue Query accepts reactive values throughout the options:

Watching Query Results

Query results are reactive refs that work with Vue’s watch:

Vue 2 vs Vue 3

Vue 2 with Composition API

Vue 3 with Script Setup

The API is identical between Vue 2 and Vue 3. The only difference is how you access the Composition API.

Advanced Features

useQueries

Execute multiple queries in parallel:

Query Options Factory

useMutationState

Track all mutations globally:

useIsFetching

Show a global loading indicator:

Shallow Option

Control ref unwrapping with the shallow option:

TypeScript

Full TypeScript support with proper type inference:

DevTools Integration

Vue Query integrates with Vue DevTools:

SSR Support

For Nuxt or other SSR frameworks:

Vue-Specific Gotchas

Ref Unwrapping: Vue Query automatically unwraps refs in query options, but query results are returned as refs. Always access them with .value in script or directly in templates.
Reactive Options: You can pass entire options objects as refs or use individual refs for specific properties. Both approaches work seamlessly with Vue’s reactivity.