When to use this skill
Use this skill whenever the user wants to:
- Set up Pinia state management in Vue 3 applications
- Create stores with defineStore()
- Work with state, getters, and actions
- Use Pinia with Composition API
- Use Pinia with Options API
- Implement SSR (Server-Side Rendering) with Pinia
- Create and use Pinia plugins
- Access stores in components
- Share state between components
- Persist state with plugins
- Test Pinia stores
- Migrate from Vuex to Pinia
How to use this skill
This skill is organized to match the Pinia official documentation structure (https://pinia.vuejs.org/introduction.html, https://pinia.vuejs.org/core-concepts/, https://pinia.vuejs.org/api/). When working with Pinia:
Identify the topic from the user's request:
- Introduction/介绍 →
examples/introduction/
- Core Concepts/核心概念 →
examples/core-concepts/
- Cookbook/食谱 →
examples/cookbook/
- SSR/服务端渲染 →
examples/ssr/
- API Reference/API 参考 →
api/
Load the appropriate example file from the examples/ directory:
Introduction (介绍) - examples/introduction/:
examples/introduction/introduction.md
Core Concepts (核心概念) - examples/core-concepts/:
examples/core-concepts/actions.md
examples/core-concepts/defining-a-store.md
examples/core-concepts/getters.md
examples/core-concepts/index.md
examples/core-concepts/outside-component-usage.md
examples/core-concepts/plugins.md
examples/core-concepts/state.md
Cookbook (食谱) - examples/cookbook/:
examples/cookbook/composables.md
examples/cookbook/composing-stores.md
examples/cookbook/hot-module-replacement.md
examples/cookbook/index.md
examples/cookbook/migration-v1-v2.md
examples/cookbook/migration-v2-v3.md
examples/cookbook/migration-vuex.md
examples/cookbook/options-api.md
examples/cookbook/testing.md
examples/cookbook/vscode-snippets.md
SSR (服务端渲染) - examples/ssr/:
examples/ssr/index.md
examples/ssr/nuxt.md
Reference API documentation in the api/ directory when needed:
Pinia Core API - api/pinia/:
api/pinia/enumerations/MutationType.md
api/pinia/functions/acceptHMRUpdate.md
api/pinia/functions/createPinia.md
api/pinia/functions/defineStore.md
api/pinia/functions/disposePinia.md
api/pinia/functions/getActivePinia.md
api/pinia/functions/mapActions.md
api/pinia/functions/mapState.md
api/pinia/functions/mapStores.md
api/pinia/functions/mapWritableState.md
api/pinia/functions/setMapStoreSuffix.md
api/pinia/index.md
api/pinia/interfaces/Store.md
api/pinia/interfaces/StoreActions.md
api/pinia/interfaces/StoreDefinition.md
api/pinia/interfaces/StoreGetters.md
api/pinia/interfaces/StoreProperties.md
api/pinia/interfaces/StoreState.md
@pinia/nuxt - api/@pinia/nuxt/:
api/@pinia/nuxt/index.md
api/@pinia/nuxt/interfaces/ModuleOptions.md
api/@pinia/nuxt/variables/default.md
@pinia/testing - api/@pinia/testing/:
api/@pinia/testing/functions/createTestingPinia.md
api/@pinia/testing/index.md
api/@pinia/testing/interfaces/TestingOptions.md
api/@pinia/testing/interfaces/TestingPinia.md
Follow the specific instructions in that example file for syntax, structure, and best practices
Important Notes:
- All examples follow Pinia best practices
- Examples include both JavaScript and TypeScript versions where applicable
- Each example file includes parameters, returns, common errors, best practices, and scenarios
- Always check the example file for best practices and common patterns
Reference the official documentation when needed:
Best Practices
- Use defineStore(): Always use defineStore() to create stores
- Store naming: Use descriptive store IDs
- State structure: Keep state flat and normalized when possible
- Getters: Use getters for computed values derived from state
- Actions: Use actions for async operations and mutations
- TypeScript: Use TypeScript for type safety
- Store composition: Split large stores into smaller, focused stores
- SSR: Use proper SSR setup for server-side rendering
- Plugins: Use plugins for cross-cutting concerns
- Testing: Write tests for stores and actions
Resources
Keywords
Pinia, state management, store, Vue 3, Composition API, Options API, defineStore, state, getters, actions, plugins, SSR, server-side rendering, TypeScript, Vuex migration, 状态管理, 存储, 组合式 API, 选项式 API, 插件, 服务端渲染, 类型支持
能力边界
✅ 适用场景
- 当你需要使用此技能对应的技术栈时
- 当项目需要遵循最佳实践时
- 当需要快速上手或深入理解核心概念时
⚠️ 需要注意
- 复杂业务逻辑需要结合具体场景调整
- 性能优化需要根据实际数据量评估
❌ 不适用场景
常见陷阱 (Gotchas)
- 版本兼容性:注意框架版本与依赖库的兼容性,不同版本 API 可能有差异
- 配置文件格式:配置文件格式错误是最常见的问题,建议使用编辑器的语法检查
- 环境变量:确保所有必要的环境变量已正确设置,敏感信息不要硬编码
- 依赖冲突:多版本共存时注意依赖冲突,使用 lock 文件锁定版本
- 性能陷阱:大数据量场景下注意性能优化,避免 N+1 查询等常见问题
使用流程
Step 1: 环境准备
确保开发环境已安装必要的依赖和工具。
Step 2: 配置初始化
根据项目需求进行基础配置。
Step 3: 核心功能使用
按照示例代码实现核心功能。
Step 4: 测试验证
运行测试确保功能正常。
Step 5: 部署上线
完成开发后进行部署和监控。
1---2name: pinia3description: Provides comprehensive guidance for Pinia state management including stores, state, getters, actions, plugins, and TypeScript support. Use when the user asks about Pinia, needs to manage application state, create stores, implement state persistence, or migrate from Vuex.4license: Complete terms in LICENSE.txt5---67## When to use this skill89Use this skill whenever the user wants to:10- Set up Pinia state management in Vue 3 applications11- Create stores with defineStore()12- Work with state, getters, and actions13- Use Pinia with Composition API14- Use Pinia with Options API15- Implement SSR (Server-Side Rendering) with Pinia16- Create and use Pinia plugins17- Access stores in components18- Share state between components19- Persist state with plugins20- Test Pinia stores21- Migrate from Vuex to Pinia2223## How to use this skill2425This skill is organized to match the Pinia official documentation structure (https://pinia.vuejs.org/introduction.html, https://pinia.vuejs.org/core-concepts/, https://pinia.vuejs.org/api/). When working with Pinia:26271. **Identify the topic** from the user's request:28 - Introduction/介绍 → `examples/introduction/`29 - Core Concepts/核心概念 → `examples/core-concepts/`30 - Cookbook/食谱 → `examples/cookbook/`31 - SSR/服务端渲染 → `examples/ssr/`32 - API Reference/API 参考 → `api/`33342. **Load the appropriate example file** from the `examples/` directory:3536 **Introduction (介绍)** - `examples/introduction/`:37 - `examples/introduction/introduction.md`3839 **Core Concepts (核心概念)** - `examples/core-concepts/`:40 - `examples/core-concepts/actions.md`41 - `examples/core-concepts/defining-a-store.md`42 - `examples/core-concepts/getters.md`43 - `examples/core-concepts/index.md`44 - `examples/core-concepts/outside-component-usage.md`45 - `examples/core-concepts/plugins.md`46 - `examples/core-concepts/state.md`4748 **Cookbook (食谱)** - `examples/cookbook/`:49 - `examples/cookbook/composables.md`50 - `examples/cookbook/composing-stores.md`51 - `examples/cookbook/hot-module-replacement.md`52 - `examples/cookbook/index.md`53 - `examples/cookbook/migration-v1-v2.md`54 - `examples/cookbook/migration-v2-v3.md`55 - `examples/cookbook/migration-vuex.md`56 - `examples/cookbook/options-api.md`57 - `examples/cookbook/testing.md`58 - `examples/cookbook/vscode-snippets.md`5960 **SSR (服务端渲染)** - `examples/ssr/`:61 - `examples/ssr/index.md`62 - `examples/ssr/nuxt.md`63643. **Reference API documentation** in the `api/` directory when needed:6566 **Pinia Core API** - `api/pinia/`:67 - `api/pinia/enumerations/MutationType.md`68 - `api/pinia/functions/acceptHMRUpdate.md`69 - `api/pinia/functions/createPinia.md`70 - `api/pinia/functions/defineStore.md`71 - `api/pinia/functions/disposePinia.md`72 - `api/pinia/functions/getActivePinia.md`73 - `api/pinia/functions/mapActions.md`74 - `api/pinia/functions/mapState.md`75 - `api/pinia/functions/mapStores.md`76 - `api/pinia/functions/mapWritableState.md`77 - `api/pinia/functions/setMapStoreSuffix.md`78 - `api/pinia/index.md`79 - `api/pinia/interfaces/Store.md`80 - `api/pinia/interfaces/StoreActions.md`81 - `api/pinia/interfaces/StoreDefinition.md`82 - `api/pinia/interfaces/StoreGetters.md`83 - `api/pinia/interfaces/StoreProperties.md`84 - `api/pinia/interfaces/StoreState.md`8586 **@pinia/nuxt** - `api/@pinia/nuxt/`:87 - `api/@pinia/nuxt/index.md`88 - `api/@pinia/nuxt/interfaces/ModuleOptions.md`89 - `api/@pinia/nuxt/variables/default.md`9091 **@pinia/testing** - `api/@pinia/testing/`:92 - `api/@pinia/testing/functions/createTestingPinia.md`93 - `api/@pinia/testing/index.md`94 - `api/@pinia/testing/interfaces/TestingOptions.md`95 - `api/@pinia/testing/interfaces/TestingPinia.md`96974. **Follow the specific instructions** in that example file for syntax, structure, and best practices9899 **Important Notes**:100 - All examples follow Pinia best practices101 - Examples include both JavaScript and TypeScript versions where applicable102 - Each example file includes parameters, returns, common errors, best practices, and scenarios103 - Always check the example file for best practices and common patterns1041055. **Reference the official documentation** when needed:106 - Introduction: https://pinia.vuejs.org/introduction.html107 - Core Concepts: https://pinia.vuejs.org/core-concepts/108 - API Reference: https://pinia.vuejs.org/api/109110## Best Practices1111121. **Use defineStore()**: Always use defineStore() to create stores1132. **Store naming**: Use descriptive store IDs1143. **State structure**: Keep state flat and normalized when possible1154. **Getters**: Use getters for computed values derived from state1165. **Actions**: Use actions for async operations and mutations1176. **TypeScript**: Use TypeScript for type safety1187. **Store composition**: Split large stores into smaller, focused stores1198. **SSR**: Use proper SSR setup for server-side rendering1209. **Plugins**: Use plugins for cross-cutting concerns12110. **Testing**: Write tests for stores and actions122123## Resources124125- **Official Documentation**: https://pinia.vuejs.org/126- **Introduction**: https://pinia.vuejs.org/introduction.html127- **Core Concepts**: https://pinia.vuejs.org/core-concepts/128- **API Reference**: https://pinia.vuejs.org/api/129- **GitHub Repository**: https://github.com/vuejs/pinia130131## Keywords132133Pinia, state management, store, Vue 3, Composition API, Options API, defineStore, state, getters, actions, plugins, SSR, server-side rendering, TypeScript, Vuex migration, 状态管理, 存储, 组合式 API, 选项式 API, 插件, 服务端渲染, 类型支持134135## 能力边界136137### ✅ 适用场景138- 当你需要使用此技能对应的技术栈时139- 当项目需要遵循最佳实践时140- 当需要快速上手或深入理解核心概念时141142### ⚠️ 需要注意143- 复杂业务逻辑需要结合具体场景调整144- 性能优化需要根据实际数据量评估145146### ❌ 不适用场景147- 不相关的技术栈或框架148- 需要完全自定义的特殊场景149150## 常见陷阱 (Gotchas)1511521. **版本兼容性**:注意框架版本与依赖库的兼容性,不同版本 API 可能有差异1532. **配置文件格式**:配置文件格式错误是最常见的问题,建议使用编辑器的语法检查1543. **环境变量**:确保所有必要的环境变量已正确设置,敏感信息不要硬编码1554. **依赖冲突**:多版本共存时注意依赖冲突,使用 lock 文件锁定版本1565. **性能陷阱**:大数据量场景下注意性能优化,避免 N+1 查询等常见问题157158## 使用流程159160### Step 1: 环境准备161确保开发环境已安装必要的依赖和工具。162163### Step 2: 配置初始化164根据项目需求进行基础配置。165166### Step 3: 核心功能使用167按照示例代码实现核心功能。168169### Step 4: 测试验证170运行测试确保功能正常。171172### Step 5: 部署上线173完成开发后进行部署和监控。