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/setup-store-template.ts
View on GitHub// Setup Store Template
// Copy this template when creating new stores with Composition API style
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { acceptHMRUpdate } from 'pinia'
// Define TypeScript interfaces
interface Product {
id: number
name: string
price: number
quantity: number
}
export const useProductStore = defineStore('product', () => {
// STATE: Use ref() for reactive state
const products = ref<Product[]>([])
const loading = ref(false)
const error = ref<string | null>(null)
// GETTERS: Use computed() for derived state
const productCount = computed(() => products.value.length)
const totalValue = computed(() => {
return products.value.reduce((sum, p) => sum + (p.price * p.quantity), 0)
})
const hasProducts = computed(() => productCount.value > 0)
// Getter that takes parameters (return a function)
const getProductById = computed(() => {
return (id: number) => products.value.find(p => p.id === id)
})
// ACTIONS: Use function() for business logic
function addProduct(product: Product) {
products.value.push(product)
}
function removeProduct(id: number) {
const index = products.value.findIndex(p => p.id === id)
if (index !== -1) {
products.value.splice(index, 1)
}
}
async function fetchProducts() {
loading.value = true
error.value = null
try {
const response = await fetch('/api/products')
if (!response.ok) throw new Error('Failed to fetch products')
products.value = await response.json()
} catch (e) {
error.value = e instanceof Error ? e.message : 'Unknown error'
console.error('Error fetching products:', e)
} finally {
loading.value = false
}
}
// Action calling another store
// async function fetchProductsWithSettings() {
// const settings = useSettingsStore()
//
// // CRITICAL: Call useStore() BEFORE any await
// // This prevents SSR issues
// await fetchProducts()
//
// if (settings.showPrices) {
// // Use settings after await is safe
// }
// }
// Custom $reset() implementation (setup stores don't have built-in reset)
function $reset() {
products.value = []
loading.value = false
error.value = null
}
// MUST return all properties you want to expose
// Private properties (not returned) break SSR, DevTools, and plugins
return {
// State
products,
loading,
error,
// Getters
productCount,
totalValue,
hasProducts,
getProductById,
// Actions
addProduct,
removeProduct,
fetchProducts,
$reset
}
})
// HMR Support
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useProductStore, 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 |