Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)29k · #9843

table-state

Skill này làm gì

Skill này giải thích cách giữ các thiết lập của bảng, như trang hiện tại, trong ref của Vue và đọc chúng trong template. Skill dành cho lập trình viên Vue cần bảng và trang luôn khớp nhau.

Khi nào nên dùng

  • ✓Khi template Vue cần hiển thị trang hiện tại hoặc một thiết lập khác của bảng.
  • ✓Khi bạn cần nối phân trang của bảng với một ref hoặc giá trị computed.
  • ✓Khi một giá trị bảng được đọc trong mã script thuần không cập nhật sau một thay đổi.

Liên kết skill

https://github.com/TanStack/table/blob/main/packages/vue-table/skills/table-state/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/TanStack/table/blob/main/packages/vue-table/skills/table-state/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để số trang trong bảng Vue của tôi cập nhật trên màn hình khi tôi bấm trang tiếp theo?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill chỉ cách giữ thiết lập phân trang trong một ref, truyền nó cho bảng dưới dạng state computed kèm callback cập nhật tương ứng và đọc nó trong template.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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.

Câu hỏi thường gặp

Vì sao một giá trị đọc một lần trong script không cập nhật?

Các lần đọc nằm ngoài cơ chế theo dõi sẽ chỉ chụp một bản sao, và bản sao đó không làm mới sau này.

Tôi có nên truyền .value cho bảng không?

Không. Skill nói truyền .value một lần sẽ làm hỏng đồng bộ về sau, nên hãy giữ đầu vào reactive dưới dạng ref, giá trị computed hoặc getter.

Vẫn còn dùng table.Subscribe không?

Nó đã bị loại bỏ. Skill khuyên đọc trực tiếp các API hoặc atom của bảng trong template.

Chi tiết

Mô tả gốc của tác giả

Read and control Table v9 state in vue. Use for tracked reads, subscriptions, controlled slices, and framework-specific reactive boundaries.

repo: TanStack/table

Độ phổ biến

Sao GitHub
29k
Vị trí xếp hạng
#9843
Giấy phép
MIT
Cập nhật
21/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự