secondsky/claude-skills / plugins/pinia-v3/skills/pinia-v3
pinia-v3
VerifiedPinia v3 Vue state management with defineStore, getters, actions. Use for Vue 3 stores, Nuxt SSR, Vuex migration, or encountering store composition, hydration, testing errors.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 17.5 KB |
| assets/example-template.txt | markdown | 425 B |
| references/example-reference.md | markdown | 760 B |
| references/plugins-composables.md | markdown | 9.7 KB |
| references/ssr-and-nuxt.md | markdown | 8.2 KB |
| references/state-getters-actions.md | markdown | 10.5 KB |
| references/store-syntax-guide.md | markdown | 6.2 KB |
| references/testing-guide.md | markdown | 9.6 KB |
| references/vuex-migration-checklist.md | markdown | 9.3 KB |
| references/vuex-migration.md | markdown | 9.9 KB |
| scripts/api-store-example.ts | script | 6.9 KB |
| scripts/auth-store-example.ts | script | 5.9 KB |
| scripts/example-script.shexecutable | script | 302 B |
| scripts/option-store-template.ts | script | 2.6 KB |
| scripts/persistence-plugin.ts | script | 7.9 KB |
| scripts/setup-store-template.ts | script | 2.7 KB |
scripts/option-store-template.ts
View on GitHub// Option Store Template
// Copy this template when creating new stores with Options API style
import { defineStore, acceptHMRUpdate } from 'pinia'
// Define TypeScript interfaces for type safety
interface User {
id: number
name: string
email: string
}
interface UserState {
users: User[]
currentUser: User | null
loading: boolean
error: string | null
}
export const useUserStore = defineStore('user', {
// State: Return an object with all state properties
state: (): UserState => ({
users: [],
currentUser: null,
loading: false,
error: null
}),
// Getters: Computed properties (like computed in components)
getters: {
// Arrow function getter with state parameter
userCount: (state) => state.users.length,
// Regular function getter accessing other getters
// IMPORTANT: Must type return value when using 'this'
hasUsers(): boolean {
return this.userCount > 0
},
// Getter that returns a function (for parameters)
getUserById: (state) => {
return (userId: number) => state.users.find(u => u.id === userId)
},
// Getter accessing another store
// import { useSettingsStore } from './settings'
// userWithSettings(state) {
// const settings = useSettingsStore()
// return { ...state.currentUser, theme: settings.theme }
// }
},
// Actions: Methods for business logic and state mutations
actions: {
// Sync action
setCurrentUser(user: User | null) {
this.currentUser = user
},
// Async action with error handling
async fetchUsers() {
this.loading = true
this.error = null
try {
const response = await fetch('/api/users')
if (!response.ok) throw new Error('Failed to fetch users')
this.users = await response.json()
} catch (e) {
this.error = e instanceof Error ? e.message : 'Unknown error'
console.error('Error fetching users:', e)
} finally {
this.loading = false
}
},
// Action calling another store's action
// async fetchUserAndSettings(userId: number) {
// await this.fetchUsers()
// const settings = useSettingsStore()
// await settings.fetchSettings(userId)
// }
// Action with $patch for multiple mutations
resetUserState() {
this.$patch({
users: [],
currentUser: null,
error: null
})
}
// Or use built-in $reset() to restore initial state
// this.$reset()
}
})
// HMR Support (Hot Module Replacement)
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useUserStore, import.meta.hot))
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |