table-state
它能做什么
这项技能解释如何把表格设置,例如当前页,保存在 Vue ref 中,并在模板中读取它们。适合表格与页面必须保持同步的 Vue 开发者。
适用场景
- ✓当 Vue 模板必须显示当前页或其他表格设置的时候。
- ✓当你需要把表格的分页连接到一个 ref 或计算值的时候。
- ✓当在普通脚本代码中读取的表格值在变化后没有更新的时候。
技能链接
https://github.com/TanStack/table/blob/main/packages/vue-table/skills/table-state/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“如何让我的 Vue 表格在点击“下一页”时在屏幕上更新页码?”
每周 5 个新技能,1 分钟读完。
工作原理
它展示如何把分页设置保存在 ref 中,以计算状态的形式,配合对应的更新回调传给表格,并在模板中读取它。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Vue table state
Before starting, run intent load @tanstack/table-core#table-state for shared ownership, initialization, updates, and resets.
Read reactive state
Vue-backed atom reads track dependencies inside templates, computed, watch, or a render boundary. const page = table.atoms.pagination.get() outside tracking captures a snapshot. Keep reactive option inputs as refs, computed values, or getters; passing .value once breaks later synchronization.
table.Subscribe is deprecated. Read table APIs or atoms directly inside templates, render functions, computed getters, or watcher sources. Use a child component when reads need a separate component render boundary.
Control a slice
Keep features and columns stable. Preserve both the reactive value and its matching callback:
import { computed, ref } from 'vue'
import {
rowPaginationFeature,
tableFeatures,
useTable,
type PaginationState,
type Updater,
} from '@tanstack/vue-table'
const features = tableFeatures({ rowPaginationFeature })
const columns = [{ accessorKey: 'name' }]
const data = ref([{ name: 'Ada' }])
const pagination = ref<PaginationState>({ pageIndex: 0, pageSize: 20 })
const state = computed(() => ({ pagination: pagination.value }))
const table = useTable({
features,
columns,
data,
state,
onPaginationChange: (next: Updater<PaginationState>) => {
pagination.value =
typeof next === 'function' ? next(pagination.value) : next
},
})
const pageSize = computed(() => table.atoms.pagination.get().pageSize)
Assign the resolved updater result to the ref. For shared atom ownership, use a stable @tanstack/vue-store atom in atoms.<slice> instead of mirroring the same slice in controlled refs.
For computed-state synchronization failures, updater mistakes, or render boundaries, read reactivity details. If this task changes processing features, run intent load @tanstack/table-core#table-features and read the relevant feature references.
API discovery
Inspect node_modules/@tanstack/vue-table/dist/useTable.d.ts and reactivity.d.ts; inspect the matching core feature declarations for the controlled slice.
常见问题
为什么在脚本中读取一次的值不更新?
在追踪之外的读取只会捕获快照,而这个快照之后不会刷新。
我应该把 .value 传给表格吗?
不应该。这项技能说明,一次性传入 .value 会破坏之后的同步,因此应把响应式输入保留为 ref、计算值或 getter。
table.Subscribe 还在使用吗?
它已被弃用,这项技能建议直接在模板中读取表格 API 或原子值。
详情
作者的原始描述
Read and control Table v9 state in vue. Use for tracked reads, subscriptions, controlled slices, and framework-specific reactive boundaries.
repo: TanStack/table
热度
- GitHub 星标
- 29k
- 排名
- #9843
- 许可证
- MIT
- 更新时间
- 2026/10/21
评论
- …
同一仓库的更多技能
getting-started
29k教你的智能体如何在 Alpine.js 中使用 TanStack Table 构建并显示数据表格,涵盖设置、响应式数据和渲染行。
table-state
29k教你的智能体如何在 Alpine.js 中读取和控制表格状态,例如当前页码,使状态变化时屏幕能够更新。
devtools
29k教你的智能体如何把 Angular 表格注册到 TanStack Devtools 面板中,使开发者在构建应用时能检查每个表格。
getting-started
29k教你的智能体如何在 Angular 中创建并显示 TanStack 表格,涵盖 injectTable 设置、模板渲染和行数据的更新。