Vue Pinia

SKILL前端设计
前端设计 未标注权限 许可证不明确

Vue 3 state management with Pinia using the Composition API, covering setup stores, SSR/Nuxt integration, persistence, and testing. Use when creating or refactoring Pinia stores, deciding what state belongs in a store versus a component, wiring stores into router guards, persisting store state to storage, or testing store actions with @pinia/testing.

一句话选型结论

按资料字段整理

Vue Pinia是前端设计类的 Agent Skill,安装方式:GitHub 仓库,权限级别未标注,许可证不明确,没有现成安装命令,需按说明手动放置 SKILL.md。技能本质是给模型读的说明书,效果取决于模型与客户端;装完先用一个小任务验证,再放进正式流程。

分类前端设计 安装方式GitHub 仓库 权限级别未标注权限 许可证许可证不明确
累计安装 未标注 本周 未标注
GitHub 星标 未标注 仓库 skills
下载量 未标注 技能市场下载数
权限级别 未标注权限 安装前请确认风险范围
许可证 许可证不明确 未说明

安装

GitHub 仓库
在支持 Skills 的客户端里执行,装完问一句「你有哪些技能」验证
  1. 1
    确认客户端支持

    确认你的客户端支持 Skills(Claude、Codex、Cursor 等),并升级到较新的版本。

  2. 2
    拿到技能文件

    按安装说明或仓库 README,把 SKILL.md 放到客户端的 skills 目录(一般一个技能一个文件夹)。

  3. 3
    刷新技能列表

    重新打开客户端,或刷新技能列表,让新放进来的技能被加载。

  4. 4
    验证是否生效

    问一句「你有哪些技能」,确认列表里出现它,再拿一个小任务试跑。

技能档案

前端设计
字段来自技能仓库与公开索引,中文说明由本站标注
作者 / 维护方mindrally仓库 skills · 版本 未标注
宿主客户端未标注技能可被这些客户端加载
安装方式GitHub 仓库安装包 mindrally/skills
权限级别未标注权限安装前请确认风险范围
许可证未说明许可证不明确,商用前请自行确认条款
仓库可用性available技能仓库当前是否可访问
最近核验未标注上游最后核验时间 · 数据更新 2026-09-03
正文体量9.5 KBSKILL.md 原文大小,越大说明说明书写得越细

典型使用场景

3 类
按分类整理的常见用法,具体以 SKILL.md 为准
出页面与组件

按描述生成页面结构和组件草稿。

调整样式与布局

改间距、配色与响应式布局。

生成设计说明

把设计稿整理成开发能接的说明。

选择建议

装之前先看这几条
按条目字段给出的判断,不替你决定用不用

值得选的地方

  • 基础信息齐全,可以先按说明装一个试试。

先想清楚的地方

  • 没有标注权限级别,实际能做什么要装好后确认。
  • 许可证不明确,商用或二次分发前先到仓库确认条款。
  • 没有现成安装命令,要按安装说明或仓库 README 手动放置。
  • 没有做站内核验,内容以作者仓库为准。
  • 技能只是说明书,实际效果取决于模型与客户端,装完先用小任务试一遍。

更适合

  • 需要在前端设计场景里给模型补一套做法的人。
  • 愿意先读一遍 SKILL.md、确认它会让模型做什么的人。

不太适合

  • 对许可证要求很严、必须明确可商用的人。
  • 只想装完就自动变强、不打算看说明书的人。

同类对比

6 个同类
同分类里挑最接近的几条,字段以各自详情页为准
技能权限级别安装方式累计安装宿主客户端安装命令
Vue Pinia当前 未标注权限 GitHub 仓库 未标注 未标注 无
前端设计 只读 GitHub 仓库 882.3 万 Codex、Claude、Cursor 有
Vercel 组合模式 联网访问 GitHub 仓库 385.9 万 Codex、Claude、Cursor 有
Vercel React native skills 前端 只读 GitHub 仓库 246.9 万 Codex、Claude、Cursor 有
adapt 搜索 浏览器控制 GitHub 仓库 202.7 万 Codex、Claude、Cursor 有
使用我的浏览器 浏览器控制 GitHub 仓库 184.8 万 Codex、Claude、Cursor 有

SKILL.md 全文

9.5 KB
模型实际读到的说明书原文,来自技能仓库

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

  1. 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).
  2. Create the store file — Add one file per domain under stores/, e.g. stores/cart.ts, using defineStore('cart', () => { ... }).
  3. Define state, getters, and actions — Declare state with ref/reactive, derive values with computed, and put all writes/side effects in functions (actions).
  4. 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.
  5. Consume in components — Call the store at the top of <script setup>, destructure reactive state with storeToRefs(), and destructure actions directly.
  6. 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.
  7. Add persistence and tests — Allowlist persisted fields, validate rehydrated data, and test actions directly with @pinia/testing.

State Ownership

  • Keep component-only state in the component with ref, reactive, or computed.
  • Use Pinia for shared client state that spans routes, layouts, or unrelated component trees.
  • Use route params and query strings for shareable navigation state — don't duplicate it into a store.
  • Use Nuxt useFetch / useAsyncData, TanStack Query for Vue, or the existing API layer for server state — Pinia is for client state, not a data-fetching cache.
  • Do not copy server cache data into Pinia unless it is an intentional editable draft, offline cache, or workflow snapshot with its own lifecycle.

Store Structure

  • Prefer setup stores with defineStore('name', () => { ... }) for Vue 3 Composition API projects over the older options-API defineStore({ state, getters, actions }) form.
  • Use one store file per domain under stores/, such as stores/cart.ts or stores/session.ts.
  • Keep state, computed getters, and actions together when they represent one cohesive domain.
  • Return every state property from setup stores so Pinia can track it for devtools, SSR, and plugins — an un-returned ref is invisible to the rest of the system.
  • Keep getters pure and side-effect free; put writes, I/O, and orchestration in actions.
// stores/cart.ts
import { computed, ref } from 'vue'
import { defineStore } from 'pinia'

interface CartLine {
  id: string
  name: string
  quantity: number
  unitPrice: number
}

export const useCartStore = defineStore('cart', () => {
  const lines = ref<CartLine[]>([])

  const itemCount = computed(() =>
    lines.value.reduce((total, line) => total + line.quantity, 0),
  )

  const subtotal = computed(() =>
    lines.value.reduce((total, line) => total + line.quantity * line.unitPrice, 0),
  )

  function addLine(line: CartLine) {
    const existing = lines.value.find((item) => item.id === line.id)
    if (existing) {
      existing.quantity += line.quantity
      return
    }
    lines.value.push(line)
  }

  function removeLine(id: string) {
    lines.value = lines.value.filter((line) => line.id !== id)
  }

  function clearCart() {
    lines.value = []
  }

  return {
    lines,
    itemCount,
    subtotal,
    addLine,
    removeLine,
    clearCart,
  }
})

Component Usage

  • Call stores at the top of <script setup> or inside setup functions, getters, and actions — never conditionally, and never inside a plain .js/.ts module loaded at import time.
  • Use storeToRefs() when destructuring store state or getters in components, so reactivity is preserved.
  • Destructure actions directly when useful; actions remain bound to the store and don't need storeToRefs().
  • Avoid writing large business workflows in components; move them to store actions or composables so they're testable and reusable.
  • Prefer computed values over watchers when deriving state — a watch that just recomputes a value should usually be a computed.
<script setup lang="ts">
import { storeToRefs } from 'pinia'
import { useCartStore } from '@/stores/cart'

const cart = useCartStore()
const { itemCount, subtotal } = storeToRefs(cart)
const { clearCart } = cart
</script>

<template>
  <div>
    <p>{{ itemCount }} items — ${{ subtotal.toFixed(2) }}</p>
    <button type="button" :disabled="itemCount === 0" @click="clearCart">
      Clear cart
    </button>
  </div>
</template>

TypeScript

  • Type store state, action payloads, and API responses explicitly.
  • Avoid any; use unknown and narrow external inputs (API responses, persisted storage) before committing them to state.
  • Use interfaces for object state that is shared across components or API boundaries.
  • Prefer discriminated unions for workflow status and error state, e.g. { status: 'idle' } | { status: 'loading' } | { status: 'error'; error: string }.
  • Keep store IDs (the first argument to defineStore) stable and descriptive because they appear in devtools and persistence keys.

Actions and Side Effects

  • Actions may be sync or async; keep each action focused on one user or domain workflow.
  • Validate action inputs at the boundary before mutating store state.
  • Represent async workflows with explicit status, error, and lastUpdatedAt fields when the UI depends on them.
  • Reset stale errors before retrying an async action so a previous failure doesn't linger in the UI.
  • Keep subscriptions, intervals, sockets, and browser listeners outside stores unless the store owns their lifecycle and cleanup (e.g. an explicit connect()/disconnect() action pair).

SSR, Nuxt, and Router Guards

  • In SSR contexts, use the store inside setup, getters, or actions so Pinia can resolve the active app instance.
  • When using a store outside setup, such as in a router guard, pass the active Pinia instance if the framework requires it (Nuxt's auto-imports handle this automatically).
  • Do not read browser-only storage (localStorage, window) during server rendering — guard with import.meta.client (Nuxt) or an onMounted check.
  • In Nuxt, prefer the @pinia/nuxt integration and SSR-safe composables for data fetching instead of manually wiring a Pinia instance.
  • Avoid singleton state leaks across requests by relying on the framework-created Pinia instance per request rather than a module-level singleton.
// router guard example (outside setup)
router.beforeEach((to) => {
  const auth = useAuthStore(pinia) // pass the active Pinia instance explicitly
  if (to.meta.requiresAuth && !auth.isAuthenticated) {
    return { name: 'login' }
  }
})

Persistence

  • Persist only the fields that must survive reloads, such as preferences or incomplete local drafts.
  • Never persist secrets, access tokens, refresh tokens, raw PII, or authorization decisions in browser storage.
  • Use field allowlists and versioned migrations for persisted store schemas so old persisted shapes don't crash a new store version.
  • Treat persisted state as untrusted input and validate it before using it for critical workflows — a user can edit localStorage directly.
  • Account for hydration timing before rendering UI that depends on persisted values, especially under SSR where the server has no access to browser storage.

Testing and Tooling

  • Use @pinia/testing (createTestingPinia()) for component tests that need stores, with actions stubbed by default.
  • Test store actions directly for domain behavior and edge cases, independent of any component.
  • Reset Pinia between tests to avoid shared state leakage across test cases.
  • Add HMR support with acceptHMRUpdate() in stores when the project uses Vite HMR patterns.
  • Keep stores easy to inspect in Vue Devtools by using clear state names and focused, single-domain stores.
import { setActivePinia, createPinia } from 'pinia'
import { describe, it, expect, beforeEach } from 'vitest'
import { useCartStore } from '@/stores/cart'

describe('cart store', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
  })

  it('merges quantities for duplicate line items', () => {
    const cart = useCartStore()
    cart.addLine({ id: '1', name: 'Widget', quantity: 1, unitPrice: 10 })
    cart.addLine({ id: '1', name: 'Widget', quantity: 2, unitPrice: 10 })
    expect(cart.itemCount).toBe(3)
  })
})

Anti-Patterns

  • Do not use Pinia as a dumping ground for every reactive value — most component state should stay local.
  • Do not destructure state directly from a store without storeToRefs(); this breaks reactivity silently.
  • Do not mutate props or route objects through store actions.
  • Do not put server-only objects, request instances, DOM nodes, or timers in store state — they don't serialize and break SSR/devtools.
  • Do not create circular reads between stores in setup functions; compose stores through actions or computed values instead of having two stores read each other at module scope.

常见问题

5 问
答案由本站依据条目字段整理
Vue Pinia怎么安装?

没有现成安装命令:按安装说明或仓库 README,把 SKILL.md 放进客户端的 skills 目录(一般一个技能一个文件夹)。

Vue Pinia支持哪些客户端?

资料没有标注宿主客户端,但只要客户端支持 Skills(Claude、Codex、Cursor 等),一般都能加载。

Vue Pinia权限高吗,安全吗?

权限级别为未标注权限。安装前先看它会读取或写入哪些内容。

Vue Pinia收费吗?

本站不代收费用,也没有标注具体价格。是否收费取决于技能本身和所用的模型或客户端,正式使用前按作者说明确认。

Vue Pinia用什么许可证?

许可证标注为 未说明(许可证不明确)。商用或二次分发前请到仓库确认条款原文。

热门专题

按场景挑技能
全部专题 →

技能内容以作者仓库为准;分类、权限级别与许可证状态的中文说明为中文整理,最近核验 未标注。