跳到正文
Skillpedia
网站与界面(前端)29k · #9843

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/TanStack/table/blob/main/packages/vue-table/skills/table-state/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能