Access stores in components: const store = useCounterStore().
Use store.$reset() (Options API stores only) to reset state to initial values.
Details
Pinia is the official state management library for Vue 3. It replaces Vuex with a simpler, type-safe API. Pinia stores are reactive — components that use store state automatically re-render when it changes. Stores are lazy-loaded on first use.
Trade-offs:
Adds a dependency — for simple apps, provide/inject or composables may suffice
Setup-style stores cannot use $reset() — you must implement reset logic manually
Stores are singletons by default — in SSR, each request needs its own Pinia instance to avoid cross-request state pollution
When NOT to use:
For component-local state — use ref() or reactive() in <script setup>
For parent-child communication — use props and emits
When the state is only shared between a parent and its direct children — use provide/inject
Read the instructions and examples in this document.
Apply the patterns to your implementation, adapting to your specific context.
Verify your implementation against the details and edge cases listed above.
Harness Integration
Type: knowledge — this skill is a reference document, not a procedural workflow.
No tools or state — consumed as context by other skills and agents.
Success Criteria
The patterns described in this document are applied correctly in the implementation.
Edge cases and anti-patterns listed in this document are avoided.
1---2name: vue-pinia-pattern3description: Vue Pinia Pattern4---5# Vue Pinia Pattern67> Manage shared application state with Pinia stores in the Options or Setup style89## When to Use1011- Multiple components across different parts of the app need to share and mutate the same state12- You need DevTools integration for state inspection, time-travel debugging, and hot-module replacement13- Replacing Vuex in a Vue 3 application1415## Instructions16171. Define a store with `defineStore('id', { state, getters, actions })` or the Setup syntax.182. Prefer the Setup syntax for composable-style stores: `defineStore('id', () => { ... })`.193. Use `storeToRefs()` when destructuring reactive state from a store.204. Keep stores focused — one store per domain concept, not one global store.2122```typescript23import { defineStore } from 'pinia';24import { ref, computed } from 'vue';2526export const useCounterStore = defineStore('counter', () => {27 const count = ref(0);28 const doubled = computed(() => count.value * 2);29 function increment() {30 count.value++;31 }32 return { count, doubled, increment };33});34```35365. Access stores in components: `const store = useCounterStore()`.376. Use `store.$reset()` (Options API stores only) to reset state to initial values.3839## Details4041Pinia is the official state management library for Vue 3. It replaces Vuex with a simpler, type-safe API. Pinia stores are reactive — components that use store state automatically re-render when it changes. Stores are lazy-loaded on first use.4243**Trade-offs:**4445- Adds a dependency — for simple apps, `provide`/`inject` or composables may suffice46- Setup-style stores cannot use `$reset()` — you must implement reset logic manually47- Stores are singletons by default — in SSR, each request needs its own Pinia instance to avoid cross-request state pollution4849**When NOT to use:**5051- For component-local state — use `ref()` or `reactive()` in `<script setup>`52- For parent-child communication — use props and emits53- When the state is only shared between a parent and its direct children — use `provide`/`inject`5455## Source5657https://patterns.dev/vue/pinia-pattern5859## Process60611. Read the instructions and examples in this document.622. Apply the patterns to your implementation, adapting to your specific context.633. Verify your implementation against the details and edge cases listed above.6465## Harness Integration6667- **Type:** knowledge — this skill is a reference document, not a procedural workflow.68- **No tools or state** — consumed as context by other skills and agents.6970## Success Criteria7172- The patterns described in this document are applied correctly in the implementation.73- Edge cases and anti-patterns listed in this document are avoided.
Run npx skillmds@latest add intense-visions/vue-pinia-pattern in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Vue Pinia Pattern It is listed under Web & Frontend on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Intense-Visions (@intense-visions) published this skill. Their other Agent Skills are listed on their SkillMD profile.