Master Pinia State Management - Stores, Actions, Getters, Plugins, Persistence
Teaches scalable state management using Pinia stores, actions, and getters. Triggers when building Vue apps that need shared state, handling async operations, or designing store architecture for small to large applications.
/plugin marketplace add pluginagentmarketplace/custom-plugin-vue/plugin install vue-assistant@pluginagentmarketplace-vueThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/schema.jsonreferences/GUIDE.mdreferences/PATTERNS.mdscripts/validate.pyProduction-grade skill for mastering Pinia state management in Vue applications.
Single Responsibility: Teach scalable state management patterns with Pinia including store design, actions, getters, plugins, and persistence strategies.
interface PiniaParams {
topic: 'stores' | 'actions' | 'getters' | 'plugins' | 'persistence' | 'all';
level: 'beginner' | 'intermediate' | 'advanced';
context?: {
app_size?: 'small' | 'medium' | 'large';
existing_state?: string[];
};
}
Prerequisites: vue-composition-api
Duration: 2-3 hours
Outcome: Create and use Pinia stores
| Topic | Concept | Exercise |
|---|---|---|
| Setup | Install and configure | App setup |
| defineStore | Create stores | Counter store |
| State | Reactive state | User store |
| Using stores | storeToRefs | Component access |
Store Syntax Comparison:
// Options Store
defineStore('counter', {
state: () => ({ count: 0 }),
getters: { double: (s) => s.count * 2 },
actions: { increment() { this.count++ } }
})
// Setup Store (Recommended)
defineStore('counter', () => {
const count = ref(0)
const double = computed(() => count.value * 2)
function increment() { count.value++ }
return { count, double, increment }
})
Prerequisites: Module 1
Duration: 2-3 hours
Outcome: Handle async operations
| Pattern | Use Case | Exercise |
|---|---|---|
| Sync actions | Simple mutations | Cart updates |
| Async actions | API calls | Fetch users |
| Error handling | Try/catch | Error states |
| Loading states | UX feedback | Spinners |
| Optimistic updates | Fast UX | Instant feedback |
Prerequisites: Module 2
Duration: 1-2 hours
Outcome: Derive and filter state
| Pattern | Use Case | Exercise |
|---|---|---|
| Simple getter | Derived value | Full name |
| Parameterized | Filtered access | Find by ID |
| Cross-store | Compose stores | Cart with products |
| Memoization | Performance | Expensive calcs |
Prerequisites: Modules 1-3
Duration: 3-4 hours
Outcome: Design scalable store structure
Architecture Patterns:
stores/
├── modules/
│ ├── useUserStore.ts # User domain
│ ├── useProductStore.ts # Product domain
│ └── useCartStore.ts # Cart domain
├── shared/
│ └── useNotificationStore.ts
└── index.ts # Re-exports
| Pattern | Description | When to Use |
|---|---|---|
| Domain stores | One per feature | Large apps |
| Composed stores | Store uses store | Related data |
| Normalized state | ID-based lookup | Many entities |
| Module pattern | Organized exports | Team projects |
Prerequisites: Modules 1-4
Duration: 2-3 hours
Outcome: Extend Pinia functionality
| Plugin | Function | Exercise |
|---|---|---|
| Logger | Dev debugging | Action logging |
| Persisted State | LocalStorage | Auth persistence |
| Reset | State reset | Logout cleanup |
| Custom | Domain-specific | Analytics |
const skillConfig = {
maxAttempts: 3,
backoffMs: [1000, 2000, 4000],
onFailure: 'simplify_store_design'
}
tracking:
- event: store_created
data: [store_name, store_type]
- event: pattern_applied
data: [pattern_name, success]
- event: skill_completed
data: [stores_built, complexity]
| Issue | Cause | Solution |
|---|---|---|
| Store not reactive | Destructured state | Use storeToRefs() |
| Circular dependency | A→B→A imports | Lazy import or reorganize |
| No active Pinia | Used before app.use | Check setup order |
| HMR not working | Missing acceptHMRUpdate | Add HMR config |
import { describe, it, expect, beforeEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { useUserStore } from './useUserStore'
describe('useUserStore', () => {
beforeEach(() => {
setActivePinia(createPinia())
})
it('initializes with null user', () => {
const store = useUserStore()
expect(store.user).toBeNull()
})
it('logs in user correctly', async () => {
const store = useUserStore()
await store.login({ email: 'test@example.com' })
expect(store.isLoggedIn).toBe(true)
})
it('logs out and clears state', () => {
const store = useUserStore()
store.$patch({ user: { id: '1', name: 'Test' } })
store.logout()
expect(store.user).toBeNull()
})
})
Skill("vue-pinia")
vue-composition-api - Prerequisitevue-typescript - Typed storesvue-testing - Store testingThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.