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

pinia

Skill này làm gì

Skill này giải thích cách tổ chức dữ liệu dùng chung trong ứng dụng Vue bằng Pinia, thư viện state chính thức của Vue. Skill dành cho lập trình viên cần cùng một dữ liệu ở nhiều phần của ứng dụng.

Khi nào nên dùng

  • ✓Khi bạn đang xây dựng ứng dụng Vue và cần dữ liệu dùng chung cho nhiều component.
  • ✓Khi bạn muốn thiết lập store với state, getter và action.
  • ✓Khi bạn cần kiểm thử hoặc mở rộng một Pinia store.

Liên kết skill

https://github.com/antfu/skills/blob/main/skills/pinia/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/antfu/skills/blob/main/skills/pinia/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

“Tạo một Pinia store giữ các sản phẩm trong giỏ hàng và tổng tiền của tôi trên mọi trang.”

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

Cách hoạt động

Agent thiết lập các store giữ dữ liệu dùng chung và các action thay đổi dữ liệu đó, theo hướng dẫn của Pinia về kiểu dữ liệu, kiểm thử và mở rộng.

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.

Pinia

Pinia is the official state management library for Vue, designed to be intuitive and type-safe. It supports both Options API and Composition API styles, with first-class TypeScript support and devtools integration.

The skill is based on Pinia v4.0.3, generated at 2026-09-25.

Core References

Topic Description Reference
Stores Defining stores, state, getters, actions, storeToRefs, subscriptions core-stores

Features

Extensibility

Topic Description Reference
Plugins Extend stores with custom properties, state, and behavior features-plugins

Composability

Topic Description Reference
Composables Using Vue composables within stores (VueUse, etc.) features-composables
Composing Stores Store-to-store communication, avoiding circular dependencies features-composing-stores

Best Practices

Topic Description Reference
Testing Unit testing with @pinia/testing, mocking, stubbing best-practices-testing
Outside Components Using stores in navigation guards, plugins, middlewares best-practices-outside-component

Advanced

Topic Description Reference
SSR Server-side rendering, state hydration advanced-ssr
Nuxt Nuxt integration, auto-imports, SSR best practices advanced-nuxt
HMR Hot module replacement for development advanced-hmr

Key Recommendations

  • Prefer Setup Stores for complex logic, composables, and watchers
  • Use storeToRefs() when destructuring state/getters to preserve reactivity
  • Actions can be destructured directly - they're bound to the store
  • Call stores inside functions not at module scope, especially for SSR
  • Add HMR support to each store for better development experience
  • Use @pinia/testing for component tests with mocked stores
Câu hỏi thường gặp

Pinia chỉ dùng cho Vue thôi à?

Pinia được xây dựng cho ứng dụng Vue, và đó là phần hướng dẫn bao quát.

Tôi có thể kiểm thử store không?

Có. Hướng dẫn bao quát việc kiểm thử và giả lập store.

Pinia có làm việc với TypeScript không?

Có. Pinia được thiết kế an toàn kiểu và hỗ trợ TypeScript.

Chi tiết

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

Pinia official Vue state management library, type-safe and extensible. Use when defining stores, working with state/getters/actions, or implementing store patterns in Vue apps.

repo: antfu/skills

Độ phổ biến

Sao GitHub
6.0k
Vị trí xếp hạng
#14442
Giấy phép
MIT
Cập nhật
30/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ự