Registry / http-networking / vue-query

vue-query

JSON →
library1.26.0jsnpmunverified

Vue Query is a library designed to simplify data fetching, caching, and synchronization for Vue applications, bringing the powerful features of TanStack Query (formerly React Query) to the Vue ecosystem. It provides a set of hooks for declarative and efficient management of asynchronous data, reducing boilerplate and improving developer experience. The current stable version is 1.26.0, but version 2.x is under active beta development, which tightly aligns its core logic with `@tanstack/query-core`. This alignment in v2 is a key differentiator, ensuring consistency with the broader TanStack Query ecosystem. It addresses common challenges like caching, background refetching, optimistic updates, and pagination out-of-the-box, making it an advanced solution compared to manual `fetch` or `axios` implementations. The library is actively maintained with ongoing feature development and bug fixes.

npm install vue-query
INSTALL
IMPORT
SIG · VUE-QUERY
V
vue-query
http-networkingjavascriptv1.26.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

QueryClient
import { QueryClient } from 'vue-query'
const QueryClient = require('vue-query')
Used to create a new instance of the query client.
QueryClientProvider
import { QueryClientProvider } from 'vue-query'
import QueryClientProvider from 'vue-query'
A component that makes the QueryClient instance available to all child components. It's a named import, not a default.
useQuery
import { useQuery } from 'vue-query'
import { useQueries } from 'vue-query'
The primary hook for fetching and managing server-side data. 'useQueries' is for fetching multiple queries in parallel.
useMutation
import { useMutation } from 'vue-query'
Used for sending data to the server (e.g., POST, PUT, DELETE requests).

This quickstart demonstrates how to set up `vue-query` in a Vue 3 application. It initializes a `QueryClient`, provides it via `QueryClientProvider`, and then uses `useQuery` within a component to fetch and display data from a public API, handling loading and error states.

import { createApp, defineComponent } from 'vue'; import { QueryClient, QueryClientProvider, useQuery } from 'vue-query'; const queryClient = new QueryClient(); const fetchTodos = async () => { const response = await fetch('https://jsonplaceholder.typicode.com/todos/1'); if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }; const App = defineComponent({ name: 'App', setup() { const { data, isLoading, isError, error } = useQuery('todo', fetchTodos); return { data, isLoading, isError, error, }; }, template: ` <div> <h1>My Todo</h1> <p v-if="isLoading">Loading todo...</p> <p v-else-if="isError">Error: {{ error.message }}</p> <div v-else> <p>ID: {{ data.id }}</p> <p>Title: {{ data.title }}</p> <p>Completed: {{ data.completed ? 'Yes' : 'No' }}</p> </div> </div> `, }); const app = createApp({ render() { return [ h(QueryClientProvider, { client: queryClient }, { default: () => h(App) }) ]; } }); app.mount('#app');
Debug
Known issues
breakingVersion 2.0.0-beta and later migrates to `@tanstack/query-core`, which may introduce breaking changes in configuration options, API, and internal behavior. It's recommended to consult the TanStack Query documentation for core changes when upgrading to `vue-query` v2.
fix
Review the official migration guide for `@tanstack/query` and `vue-query` v2 when it becomes stable. Specifically, check for changes related to query keys, query options, and client configuration.
affects: >=2.0.0-beta.1
breakingStarting from v2.0.0-beta.10, `vue-query` is updated to be ESM compliant, aligning with `query-core`'s move to ESM. This might affect bundler configurations or environments that rely strictly on CommonJS.
fix
Ensure your project is configured for ESM by using `"type": "module"` in your `package.json` or by configuring your bundler (e.g., Webpack, Rollup, Vite) to correctly handle ESM imports and exports for `vue-query`.
affects: >=2.0.0-beta.10
gotcha`vue-query` requires the Vue Composition API. For Vue 2 projects, you must explicitly install and register either `@vue/composition-api` or `@nuxtjs/composition-api` (for Nuxt 2). For Vue 3, the Composition API is built-in.
fix
For Vue 2, install `npm install @vue/composition-api` and then `Vue.use(VueCompositionAPI)` in your main.js. For Nuxt 2, install `@nuxtjs/composition-api` and ensure it's configured in `nuxt.config.js`.
affects: >=1.0.0
gotchaAll `vue-query` hooks (e.g., `useQuery`, `useMutation`) must be called within a component's `setup()` function or another Composition API hook. Calling them outside will result in errors related to missing context.
fix
Ensure that `useQuery` and other hooks are invoked directly within the `setup()` function of a Vue component or within a custom composable function that is itself called from `setup()`.
affects: >=1.0.0
Errors
Common errors & fixes
Failed to resolve component: QueryClientProvider
`QueryClientProvider` was not correctly imported or registered as a component, often due to incorrect casing or not using named import.
fix
Ensure `import { QueryClientProvider } from 'vue-query';` is used and that you are rendering it correctly in your template or render function, e.g., `<QueryClientProvider :client="queryClient">` or `h(QueryClientProvider, { client: queryClient }, ...)`. Remember it's a named export.
Error: A QueryClient was not found in the Vue context. Did you forget to install the QueryClientProvider?
The `QueryClientProvider` component was not used to wrap the application or the component attempting to use `vue-query` hooks, or the `client` prop was not passed.
fix
Wrap your root Vue component (or the relevant part of your app) with `<QueryClientProvider :client="queryClient">` and ensure `queryClient` is an instance of `new QueryClient()`.
TypeError: Cannot read properties of undefined (reading 'setup')
This usually indicates that a `vue-query` hook (or any Composition API hook) is being called outside of a Vue component's `setup()` function context.
fix
Verify that `useQuery`, `useMutation`, etc., are only called directly within the `setup()` method of your components or within custom composable functions that are themselves called from `setup()`.
Upgrade
Version history
1.26.0latest on npm
Audit
Dependencies
@nuxtjs/composition-apioptionalRequired for Nuxt 2 applications using the Composition API.
@vue/composition-apioptionalRequired for Vue 2 applications using the Composition API.
vuerequiredCore dependency for Vue.js applications.
Agent activity
18 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
vue-query — npm install vue-query · libregistry