@tanstack/vue-query

中文文档
5.105.2发布于 2026/11/02MITTypeScriptESM + CJS构建来源已验证

Hooks for managing, caching and syncing asynchronous and remote data in Vue

原始使用文档
TanStack Vue Query
[![Vue Query logo](https://raw.githubusercontent.com/TanStack/query/main/packages/vue-query/media/vue-query.png)](https://github.com/TanStack/query/tree/main/packages/vue-query)

npm version npm license bundle size npm

Vue Query

Hooks for fetching, caching and updating asynchronous data in Vue.

Support for Vue 2.x via vue-demi

Documentation

Visit https://tanstack.com/query/latest/docs/vue/overview

Quick Features

  • Transport/protocol/backend agnostic data fetching (REST, GraphQL, promises, whatever!)
  • Auto Caching + Refetching (stale-while-revalidate, Window Refocus, Polling/Realtime)
  • Parallel + Dependent Queries
  • Mutations + Reactive Query Refetching
  • Multi-layer Cache + Automatic Garbage Collection
  • Paginated + Cursor-based Queries
  • Load-More + Infinite Scroll Queries w/ Scroll Recovery
  • Request Cancellation
  • (experimental) Suspense + Fetch-As-You-Render Query Prefetching
  • (experimental) SSR support
  • Dedicated Devtools
  • npm bundle size (depending on features imported)

Quick Start

  1. Install vue-query

    $ npm i @tanstack/vue-query
    

    or

    $ pnpm add @tanstack/vue-query
    

    or

    $ yarn add @tanstack/vue-query
    

    or

    $ bun add @tanstack/vue-query
    

    If you are using Vue 2.6, make sure to also setup @vue/composition-api

  2. Initialize Vue Query via VueQueryPlugin

    import { createApp } from 'vue'
    import { VueQueryPlugin } from '@tanstack/vue-query'
    
    import App from './App.vue'
    
    createApp(App).use(VueQueryPlugin).mount('#app')
    
  3. Use query

    import { defineComponent } from 'vue'
    import { useQuery } from '@tanstack/vue-query'
    
    export default defineComponent({
      name: 'MyComponent',
      setup() {
        const query = useQuery({ queryKey: ['todos'], queryFn: getTodos })
    
        return {
          query,
        }
      },
    })
    
  4. If you need to update options on your query dynamically, make sure to pass them as reactive variables

    const id = ref(1)
    const enabled = ref(false)
    
    const query = useQuery({
      queryKey: ['todos', id],
      queryFn: () => getTodos(id),
      enabled,
    })
    

版本与发布记录

@tanstack/vue-query 共发布 491 个版本,首次发布于 2022/10/03;过去 12 个月发布了 76 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.105.2latest2026/11/02今天
5.105.12026/11/012 天前
5.105.02026/10/268 天前
5.104.52026/10/2014 天前
5.104.42026/10/1816 天前
5.104.32026/10/1519 天前

其他发布通道:alpha → 5.0.0-alpha.91,beta → 5.0.0-beta.35,rc → 5.0.0-rc.16,previous → 4.44.0。

关于 @tanstack/vue-query 的常见问题

@tanstack/vue-query 是什么?

Vue中用于管理、缓存和同步异步和远程数据的钩子

如何安装 @tanstack/vue-query?

在项目目录运行 npm install @tanstack/vue-query,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(^2.6.0 || ^3.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@tanstack/vue-query 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@tanstack/vue-query 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@tanstack/vue-query 可以商用吗?

@tanstack/vue-query 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@tanstack/vue-query 还在维护吗?

最新版本 5.105.2 发布于 2026/11/02(今天);至今共发布 491 个版本,其中过去 12 个月发布了 76 个;首次发布于 2022/10/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。