skills/pinia/SKILL.md
Pinia state management for Vue 3 using Composition API (Setup Stores) — TypeScript-first, storeToRefs for reactivity, focused stores, and API calls in composables. Use when the project uses Vue 3 Composition API / <script setup>.
npx skillsauth add vuluu2k/skills piniaInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill focuses on Setup Stores with TypeScript and using them inside Composition API /
<script setup>components.
storeToRefs when destructuring state from stores to maintain reactivity.| Topic | Description | Reference |
|-------|-------------|-----------|
| Setup Stores | Define stores with ref, computed, functions inside defineStore | setup-stores |
| Using in Components | storeToRefs, direct action calls in <script setup> | using-in-components |
| API in Composables | Separate API calls from store actions via composable functions | api-in-composables |
// stores/counter.ts
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
const name = ref('My App')
const doubled = computed(() => count.value * 2)
function increment() {
count.value++
}
return { count, name, doubled, increment }
})
<script setup> Component<script setup lang="ts">
import { storeToRefs } from 'pinia'
import { useCounterStore } from '@/stores/counter'
const store = useCounterStore()
// ✅ Use storeToRefs to keep reactivity when destructuring state/getters
const { count, doubled } = storeToRefs(store)
// ✅ Actions can be destructured directly (they are plain functions)
const { increment } = store
</script>
<template>
<p>Count: {{ count }} | Doubled: {{ doubled }}</p>
<button @click="increment">Increment</button>
</template>
// composables/useCounterApi.ts
import { useCounterStore } from '@/stores/counter'
export function useCounterApi() {
const store = useCounterStore()
async function fetchCount() {
const data = await fetch('/api/counter').then(r => r.json())
store.count = data.count
}
return { fetchCount }
}
<script setup lang="ts">
import { useCounterApi } from '@/composables/useCounterApi'
const { fetchCount } = useCounterApi()
</script>
useStore() at module top-level — only inside setup() / <script setup> / composables.storeToRefs extracts reactive refs for state and getters; actions remain plain functions and don't need storeToRefs.development
Vue 3 Composition API — <script setup>, reactivity (shallowRef/ref), props without destructure, computed, watch, provide/inject, and composables. Use when the project uses modern Vue 3 Composition API style.
development
Vue 3 Options API — data, props, computed, methods, watch, emits, provide/inject, lifecycle hooks, and mixins. Use when the project uses Options API style (Vue 2 legacy or explicit Vue 3 Options API preference).
tools
Best practices for mixing Ant Design Vue components with Tailwind CSS utility classes. Use this skill to keep styling consistent without custom CSS files.
development
Pinia state management for Vue using Options API style — define stores with state, getters, actions, and use them in Options API components via mapState/mapWritableState/mapActions.