vue-pinia
Installation
SKILL.md
Vue + Pinia
Pinia is the standard state management library for Vue 3, and setup stores built with the Composition API give shared application state the same ergonomics as local ref/computed state.
Workflow for Adding a Pinia Store
- Decide if Pinia is the right tool — Confirm the state is shared across routes/components, not server cache data, and not purely local UI state (see State Ownership below).
- Create the store file — Add one file per domain under
stores/, e.g.stores/cart.ts, usingdefineStore('cart', () => { ... }). - Define state, getters, and actions — Declare state with
ref/reactive, derive values withcomputed, and put all writes/side effects in functions (actions). - Return everything from the setup function — Return every piece of state, every getter, and every action so Pinia devtools, SSR, and plugins can track them.
- Consume in components — Call the store at the top of
<script setup>, destructure reactive state withstoreToRefs(), and destructure actions directly. - Handle SSR/router-guard usage — Call the store from inside setup, a getter, an action, or pass the active Pinia instance explicitly outside setup contexts.
- Add persistence and tests — Allowlist persisted fields, validate rehydrated data, and test actions directly with
@pinia/testing.