All skills
onmax avatar

/pinia

@de09c7b official
by Maxonmax/nuxt-skills715 stars
38

Pinia official Vue state management library, type-safe and extensible. Use when defining stores, working with state/getters/actions, or implementing store patterns in Vue apps.

Use this Skill: https://skilld.dev/gh/onmax/nuxt-skills/pinia

This session only. Nothing lands on disk.

referencesadvanced-nuxt.md

≈631 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Nuxt Integration

Pinia works seamlessly with Nuxt 3/4, handling SSR, serialization, and XSS protection automatically.

Installation

npx nuxi@latest module add pinia

This installs both @pinia/nuxt and pinia. If pinia isn't installed, add it manually.

npm users: If you get ERESOLVE unable to resolve dependency tree, add to package.json:

"overrides": { "vue": "latest" }

Configuration

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@pinia/nuxt'],
})

Auto Imports

These are automatically available:

  • usePinia() - get pinia instance
  • defineStore() - define stores
  • storeToRefs() - extract reactive refs
  • acceptHMRUpdate() - HMR support

All stores in app/stores/ (Nuxt 4) or stores/ are auto-imported.

Custom Store Directories

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@pinia/nuxt'],
  pinia: {
    storesDirs: ['./stores/**', './custom-folder/stores/**'],
  },
})

Fetching Data in Pages

Use callOnce() for SSR-friendly data fetching:

<script setup>
const store = useStore()

// Run once, data persists across navigations
await callOnce('user', () => store.fetchUser())
</script>

Refetch on Navigation

<script setup>
const store = useStore()

// Refetch on every navigation (like useFetch)
await callOnce('user', () => store.fetchUser(), { mode: 'navigation' })
</script>

Using Stores Outside Components

In navigation guards, middlewares, or other stores, pass the pinia instance:

// middleware/auth.ts
export default defineNuxtRouteMiddleware((to) => {
  const nuxtApp = useNuxtApp()
  const store = useStore(nuxtApp.$pinia)

  if (to.meta.requiresAuth && !store.isLoggedIn) {
    return navigateTo('/login')
  }
})

Most of the time, you don't need this - just use stores in components or other injection-aware contexts.

Pinia Plugins with Nuxt

Create a Nuxt plugin:

// plugins/myPiniaPlugin.ts
import { PiniaPluginContext } from 'pinia'

function MyPiniaPlugin({ store }: PiniaPluginContext) {
  store.$subscribe((mutation) => {
    console.log(`[🍍 ${mutation.storeId}]: ${mutation.type}`)
  })
  return { creationTime: new Date() }
}

export default defineNuxtPlugin(({ $pinia }) => {
  $pinia.use(MyPiniaPlugin)
})
<!-- Source references: - https://pinia.vuejs.org/ssr/nuxt.html -->

Source: SKILL.md on GitHub

No alerts9d3 checks · Risk SAFE
  • Gen Agent Trust Hub9d

    The skill provides comprehensive documentation and best practices for the Pinia state management library. It covers defining stores, using plugins, SSR hydration, and unit testing. No malicious patterns or security risks were identified; the skill includes security-conscious recommendations like using 'devalue' for XSS-safe serialization during server-side rendering.

  • Socket9d

    No alerts

  • Snyk9d

    Risk: LOW · No issues

Signed by skilld at de09c7b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated last week
Other metadata
metadata
{
  "author": "Anthony Fu",
  "version": "2026.1.28",
  "source": "Generated from https://github.com/vuejs/pinia, scripts located at https://github.com/antfu/skills"
}

README badge

README badge for onmax/nuxt-skills/pinia