[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M70HB7HH010RX7D0NBTYYFBG":3,"skill-same:01M70HB7HH010RX7D0NBTYYFBG":77},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":28,"publishedAt":49,"linkOnly":50,"markdownContent":51,"markdownBody":52,"frontMatter":53,"refName":55,"commitSha":56,"skillDirectory":57,"forksCount":58,"repositoryHtmlUrl":59,"repositoryHomepageUrl":6,"ownerHtmlUrl":60,"ownerBlogUrl":6,"ownerDescription":61,"updatedAt":62,"install":63,"resources":76},"01M70HB7HH010RX7D0NBTYYFBG","vue-patterns",null,"Vue.js 3 Composition API patterns, component architecture, reactivity best practices, Pinia state management, Vue Router navigation, and Nuxt SSR patterns. Activates for Vue, Nuxt, Vite, or Pinia projects. Use when building or reviewing Vue 3, Nuxt, or Pinia code — Composition API, reactivity, or router navigation.","mdnaimul22\u002Fhuman-skills","mdnaimul22","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F64520358?v=4","01M70FH95MH2H796Q01TYSFZ03","Naimul","01M70FH96798CQR4YHA13F17GA",3,"MIT","https:\u002F\u002Fgithub.com\u002Fmdnaimul22\u002Fhuman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstorage\u002Faffaan-m_ECC\u002Fvue-patterns\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000009","前端开发","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48],"patterns","vue","vue patterns","use","vite","nuxt","for","api patterns","ssr","component","pinia","router","api","architecture","code","when","component architecture","Composition","pinia state","projects","2026-11-10 10:12:30",false,"---\nname: vue-patterns\ndescription: Vue.js 3 Composition API patterns, component architecture, reactivity best practices, Pinia state management, Vue Router navigation, and Nuxt SSR patterns. Activates for Vue, Nuxt, Vite, or Pinia projects. Use when building or reviewing Vue 3, Nuxt, or Pinia code — Composition API, reactivity, or router navigation.\norigin: ECC\n---\n\n# Vue.js Patterns and Best Practices\n\nComprehensive guide for Vue.js 3 development using Composition API (`\u003Cscript setup>`), covering component design, reactivity, state management, routing, testing, and SSR patterns. Nuxt-specific guidance is included where it differs from vanilla Vue.\n\n## When to Activate\n\nActivate this skill when:\n- The project uses Vue.js (any version), Nuxt, Vite + Vue, or Pinia.\n- The user asks about Vue component architecture, composables, reactivity, or state management.\n- Reviewing Vue Single-File Components (`.vue` files).\n- Setting up Vue Router, Pinia stores, or Vite\u002FVitest configuration.\n- Discussing Vue-specific performance, security, or SSR patterns.\n\n---\n\n## 1. Project Structure\n\n### Recommended Layout (Feature-First)\n\n```\nsrc\u002F\n├── api\u002F              # API client and endpoint definitions\n├── assets\u002F           # Static assets (images, fonts, icons)\n├── components\u002F       # Shared\u002Freusable components\n│   ├── base\u002F         # Base UI primitives (Button, Input, Modal)\n│   └── features\u002F     # Feature-specific shared components\n├── composables\u002F      # Reusable Composition API logic\n├── layouts\u002F          # Page layouts (optional)\n├── pages\u002F            # Route-level page components\n├── router\u002F           # Vue Router configuration\n├── stores\u002F           # Pinia stores\n├── types\u002F            # TypeScript type definitions\n├── utils\u002F            # Pure utility functions\n└── App.vue           # Root component\n```\n\n### File Naming\n\n| Convention | When to Use |\n|-----------|-------------|\n| `PascalCase.vue` | All components (enforced by `vue\u002Fmulti-word-component-names`) |\n| `useCamelCase.ts` | Composables |\n| `camelCase.ts` | Utilities, API clients, types |\n| `kebab-case` directories | Route segments, feature folders |\n\n---\n\n## 2. Component Architecture\n\n### Single-File Component Order\n\n```vue\n\u003Cscript setup lang=\"ts\">\n\u002F\u002F 1. Imports (vue → ecosystem → absolute → relative)\n\u002F\u002F 2. Props & Emits & Slots\n\u002F\u002F 3. Composables\n\u002F\u002F 4. Local state (ref\u002Freactive)\n\u002F\u002F 5. Computed properties\n\u002F\u002F 6. Methods\n\u002F\u002F 7. Watchers\n\u002F\u002F 8. Lifecycle hooks\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003C!-- Template content -->\n\u003C\u002Ftemplate>\n\n\u003Cstyle scoped>\n  \u002F* Scoped styles *\u002F\n\u003C\u002Fstyle>\n```\n\n### Presentational vs Container\n\n- **Container components**: Own data fetching, state, and side effects. Render presentational components.\n- **Presentational components**: Receive props, emit events. No API calls, no store access. Pure rendering.\n\n### Props Best Practices\n\n```ts\n\u002F\u002F Type-based props with defaults\ninterface Props {\n  label: string;\n  variant?: \"primary\" | \"secondary\";\n  disabled?: boolean;\n  items: Item[];\n}\n\nconst props = withDefaults(defineProps\u003CProps>(), {\n  variant: \"primary\",\n  disabled: false,\n});\n```\n\n- Always provide `type`, and `required`\u002F`default` where appropriate.\n- Boolean props: `isXxx`, `hasXxx`, `canXxx`.\n- Never mutate props — emit events instead.\n- For v-model binding, use `defineModel()` (Vue 3.4+) or `modelValue` + `update:modelValue`.\n\n### Events\n\n```ts\nconst emit = defineEmits\u003C{\n  submit: [];\n  \"update:modelValue\": [value: string];\n  select: [id: string, index: number];\n}>();\n```\n\n- Use kebab-case in templates (`@update:model-value`).\n- Use camelCase in script (`emit(\"update:modelValue\", val)`).\n\n---\n\n## 3. Composables (Reusable Logic)\n\n### Structure\n\n```ts\n\u002F\u002F composables\u002FuseDebounce.ts\nexport function useDebounce\u003CT>(value: MaybeRef\u003CT>, delay: number): Ref\u003CT> {\n  const debounced = ref(toValue(value)) as Ref\u003CT>;\n\n  let timer: ReturnType\u003Ctypeof setTimeout>;\n  watch(\n    () => toValue(value),\n    (newVal) => {\n      clearTimeout(timer);\n      timer = setTimeout(() => { debounced.value = newVal; }, delay);\n    }\n  );\n\n  onUnmounted(() => clearTimeout(timer));\n  return readonly(debounced);\n}\n```\n\n### Rules\n\n- Must start with `use` prefix.\n- Return reactive values (`ref`, `computed`, `reactive`), never plain primitives.\n- Accept reactive inputs via `MaybeRef` \u002F `toRef()` \u002F `toValue()`.\n- Clean up side effects in `onUnmounted` or watcher `onCleanup`.\n- No module-scope side effects.\n\n### vs Mixins\n\nComposables replace Vue 2 mixins entirely:\n- **Mixins**: Opaque data flow, source-of-truth collisions, name conflicts.\n- **Composables**: Explicit imports, clear return values, composable and tree-shakable.\n\n---\n\n## 4. State Management\n\n### When to Use What\n\n| Pattern | Use Case |\n|---------|----------|\n| `ref()` \u002F `reactive()` | Local component state |\n| Props + Emits | Parent-child communication |\n| Provide \u002F Inject | Theme, config, plugin API |\n| Pinia store | Global, shared, complex state |\n| Server state composable | API data with caching (wrap `fetch`\u002FTanStack Query) |\n\n### Pinia Setup Store (Preferred)\n\n```ts\n\u002F\u002F stores\u002FuseCartStore.ts\nexport const useCartStore = defineStore(\"cart\", () => {\n  const items = ref\u003CCartItem[]>([]);\n  const isLoading = ref(false);\n\n  const totalPrice = computed(() =>\n    items.value.reduce((sum, i) => sum + i.price * i.quantity, 0)\n  );\n  const itemCount = computed(() =>\n    items.value.reduce((sum, i) => sum + i.quantity, 0)\n  );\n\n  async function addItem(productId: string) {\n    isLoading.value = true;\n    try {\n      const item = await fetchProduct(productId);\n      const existing = items.value.find(i => i.id === item.id);\n      if (existing) existing.quantity++;\n      else items.value.push({ ...item, quantity: 1 });\n    } finally {\n      isLoading.value = false;\n    }\n  }\n\n  return { items, isLoading, totalPrice, itemCount, addItem };\n});\n```\n\n- Use Setup Store syntax (not Options Store).\n- Prefer actions for business-level mutations and `$patch()` for grouped updates.\n- Every async action: handle loading + success + error.\n\n---\n\n## 5. Vue Router\n\n### Route Definitions\n\n```ts\nconst routes = [\n  {\n    path: \"\u002Fusers\u002F:id\",\n    name: \"user-detail\",\n    component: () => import(\"@\u002Fpages\u002FUserDetail.vue\"), \u002F\u002F lazy\n    props: true, \u002F\u002F pass params as props\n    meta: { requiresAuth: true },\n  },\n];\n```\n\n### Navigation Guards\n\n```ts\nrouter.beforeEach((to, from) => {\n  const { isLoggedIn } = useAuthStore();\n  if (to.meta.requiresAuth && !isLoggedIn) {\n    return { name: \"login\", query: { redirect: to.fullPath } };\n  }\n});\n```\n\n### Reactive Route Params\n\nWhen a component stays mounted but route params change:\n\n```ts\nconst route = useRoute();\nconst id = computed(() => route.params.id as string);\nwatch(id, (newId) => fetchItem(newId));\n```\n\n---\n\n## 6. Template Patterns\n\n### Template Syntax\n\n```vue\n\u003C!-- v-if\u002Fv-else-if\u002Fv-else -->\n\u003Cdiv v-if=\"isLoading\">Loading...\u003C\u002Fdiv>\n\u003Cdiv v-else-if=\"error\">Error: {{ error }}\u003C\u002Fdiv>\n\u003Cdiv v-else>{{ content }}\u003C\u002Fdiv>\n\n\u003C!-- v-show for frequent toggles -->\n\u003Cdiv v-show=\"isOpen\">Toggled content\u003C\u002Fdiv>\n\n\u003C!-- v-for with stable keys -->\n\u003Cdiv v-for=\"item in items\" :key=\"item.id\">{{ item.name }}\u003C\u002Fdiv>\n\n\u003C!-- Computed filtered list (not v-if + v-for on same element) -->\n\u003Cdiv v-for=\"item in activeItems\" :key=\"item.id\">{{ item.name }}\u003C\u002Fdiv>\n\n\u003C!-- Event handling -->\n\u003Cform @submit.prevent=\"handleSubmit\">\n  \u003Cbutton type=\"submit\">Save\u003C\u002Fbutton>\n\u003C\u002Fform>\n\n\u003C!-- v-model -->\n\u003Cinput v-model=\"name\" \u002F>\n\u003CCustomInput v-model=\"value\" v-model:title=\"title\" \u002F>\n```\n\n---\n\n## 7. Performance\n\n| Technique | When to Use |\n|-----------|-------------|\n| `v-memo` | List items that rarely change |\n| `v-once` | Content rendered once and static forever |\n| `shallowRef()` | Large data structures replaced wholesale |\n| `shallowReactive()` | Only top-level properties are reactive |\n| `v-show` over `v-if` | Frequent visibility toggles |\n| `\u003CKeepAlive :max=\"10\">` | Cache toggled views |\n| Lazy routes | `() => import(...)` for non-critical routes |\n| `Suspense` | Async component loading with fallback |\n\n---\n\n## 8. Testing\n\n### Stack\n\n- **Vitest** for unit and component tests\n- **Vue Test Utils** for mounting and interaction\n- **@pinia\u002Ftesting** for store mocking\n- **Playwright** for E2E\n\n### Component Test Pattern\n\n```ts\nimport { mount } from \"@vue\u002Ftest-utils\";\nimport { createPinia, setActivePinia } from \"pinia\";\nimport UserCard from \".\u002FUserCard.vue\";\n\nbeforeEach(() => { setActivePinia(createPinia()); });\n\nit(\"renders and emits\", async () => {\n  const wrapper = mount(UserCard, {\n    props: { user: { id: \"1\", name: \"Alice\" } },\n  });\n  expect(wrapper.text()).toContain(\"Alice\");\n  await wrapper.find(\"button\").trigger(\"click\");\n  expect(wrapper.emitted(\"select\")![0]).toEqual([\"1\"]);\n});\n```\n\n---\n\n## 9. Nuxt-Specific Patterns\n\n### Auto-Imports\n\nNuxt auto-imports `ref`, `computed`, `watch`, `useFetch`, `useAsyncData`, etc. Use them directly without importing. For non-Nuxt projects, always import explicitly.\n\n### useAsyncData \u002F useFetch\n\n```ts\nconst { data: user, pending, error, refresh } = await useAsyncData(\n  \"user\", \u002F\u002F unique key for caching\n  () => $fetch(`\u002Fapi\u002Fusers\u002F${id}`),\n);\n\nconst { data: posts } = await useFetch(\"\u002Fapi\u002Fposts\", {\n  query: { page: 1 },\n  key: \"posts-page-1\", \u002F\u002F dedupes requests\n});\n```\n\n### Server Routes\n\n```ts\n\u002F\u002F server\u002Fapi\u002Fusers\u002F[id].ts\nexport default defineEventHandler(async (event) => {\n  const { id } = await getValidatedRouterParams(event, z.object({\n    id: z.string().uuid(),\n  }).parse);\n  \u002F\u002F ... fetch and return\n});\n```\n\n### Runtime Config\n\n```ts\n\u002F\u002F nuxt.config.ts\nexport default defineNuxtConfig({\n  runtimeConfig: {\n    \u002F\u002F server-only\n    apiSecret: \"\",\n    \u002F\u002F public (exposed to client)\n    public: {\n      apiBase: \"https:\u002F\u002Fapi.example.com\",\n    },\n  },\n});\n```\n\n---\n\n## 10. Vue 3.5+ New APIs\n\n### Reactive Props Destructure\n\nVue 3.5 stabilized reactive props destructure — destructured variables from `defineProps()` are automatically reactive:\n\n```ts\n\u002F\u002F Vue 3.5+: destructured props are reactive (no need for toRefs)\nconst { count = 0, msg = \"hello\" } = defineProps\u003C{\n  count?: number;\n  msg?: string;\n}>();\n\n\u002F\u002F Limitation: cannot watch destructured prop directly\nwatch(() => count, (newVal) => { ... }); \u002F\u002F PASS getter required\n```\n\n### `useTemplateRef()`\n\nReplace name-matched plain refs with `useTemplateRef()` for template references:\n\n```ts\nimport { useTemplateRef } from \"vue\";\nconst inputEl = useTemplateRef\u003CHTMLInputElement>(\"input\");\n\u002F\u002F \"input\" matches the ref=\"input\" attribute in template, not the variable name\n```\n\nSupports dynamic ref IDs: `useTemplateRef(dynamicRefId)`.\n\n### `onWatcherCleanup()`\n\nGlobally importable watcher cleanup API (Vue 3.5+). It must be called synchronously inside the watcher callback:\n\n```ts\nimport { watch, onWatcherCleanup } from \"vue\";\n\nwatch(userId, async (newId) => {\n  const controller = new AbortController();\n  onWatcherCleanup(() => controller.abort());\n  \u002F\u002F ... fetch with signal\n});\n```\n\n### `useId()`\n\nSSR-stable unique ID generation for form elements and accessibility:\n\n```ts\nimport { useId } from \"vue\";\nconst id = useId();\n```\n\n### `defer` Teleport\n\n`\u003CTeleport defer>` allows teleporting to targets rendered in the same cycle:\n\n```vue\n\u003CTeleport defer to=\"#container\">Content\u003C\u002FTeleport>\n\u003Cdiv id=\"container\">\u003C\u002Fdiv>\n```\n\n### Lazy Hydration (SSR)\n\n`defineAsyncComponent()` now supports `hydrate` strategy:\n\n```ts\nimport { defineAsyncComponent, hydrateOnVisible } from \"vue\";\nconst AsyncComp = defineAsyncComponent({\n  loader: () => import(\".\u002FComp.vue\"),\n  hydrate: hydrateOnVisible(),\n});\n```\n\n---\n\n## Anti-Patterns\n\n| Anti-Pattern | Why It's Wrong | The Fix |\n|-------------|---------------|---------|\n| Destructuring `defineProps()` (Vue \u003C 3.5) | Captures snapshot, loses reactivity | Access via `props.xxx` or use `toRefs()` |\n| `watch()` on destructured prop (Vue 3.5+) | Compile-time error — destructured props can't be watched directly | Use getter wrapper: `watch(() => count, ...)` |\n| `v-if` + `v-for` on same element | Ambiguous execution order | Use computed filtered array |\n| `v-for` key = index | Broken state on reorder | Use stable database IDs |\n| Mutating props | Violates one-way data flow | Emit events or use `v-model` |\n| `v-html` with user content | XSS vulnerability | Sanitize with DOMPurify |\n| Mixins in Vue 3 | Opaque, collision-prone | Replace with composables |\n| Module-scope side effects in composable | Shared across instances | Scope in `onMounted` + `onUnmounted` |\n| `reactive()` for replaceable state | Replacement breaks reactivity | Use `ref()` instead |\n| Watcher without cleanup | Memory leaks, race conditions | Use `onCleanup` or `onWatcherCleanup()` (Vue 3.5+) |\n| Options API in new Vue 3 code | Ecosystem move to Composition API | Use `\u003Cscript setup>` |\n| Plain ref for template references | No dynamic ref support, name-matching fragile | Use `useTemplateRef()` (Vue 3.5+) |\n\n## Related Skills\n\n- `accessibility` — ARIA, semantic HTML, focus management\n- `frontend-patterns` — Cross-framework frontend architecture\n- `typescript` — TypeScript best practices applied to Vue projects\n- `coding-standards` — General code quality standards\n","# Vue.js Patterns and Best Practices\n\nComprehensive guide for Vue.js 3 development using Composition API (`\u003Cscript setup>`), covering component design, reactivity, state management, routing, testing, and SSR patterns. Nuxt-specific guidance is included where it differs from vanilla Vue.\n\n## When to Activate\n\nActivate this skill when:\n- The project uses Vue.js (any version), Nuxt, Vite + Vue, or Pinia.\n- The user asks about Vue component architecture, composables, reactivity, or state management.\n- Reviewing Vue Single-File Components (`.vue` files).\n- Setting up Vue Router, Pinia stores, or Vite\u002FVitest configuration.\n- Discussing Vue-specific performance, security, or SSR patterns.\n\n---\n\n## 1. Project Structure\n\n### Recommended Layout (Feature-First)\n\n```\nsrc\u002F\n├── api\u002F              # API client and endpoint definitions\n├── assets\u002F           # Static assets (images, fonts, icons)\n├── components\u002F       # Shared\u002Freusable components\n│   ├── base\u002F         # Base UI primitives (Button, Input, Modal)\n│   └── features\u002F     # Feature-specific shared components\n├── composables\u002F      # Reusable Composition API logic\n├── layouts\u002F          # Page layouts (optional)\n├── pages\u002F            # Route-level page components\n├── router\u002F           # Vue Router configuration\n├── stores\u002F           # Pinia stores\n├── types\u002F            # TypeScript type definitions\n├── utils\u002F            # Pure utility functions\n└── App.vue           # Root component\n```\n\n### File Naming\n\n| Convention | When to Use |\n|-----------|-------------|\n| `PascalCase.vue` | All components (enforced by `vue\u002Fmulti-word-component-names`) |\n| `useCamelCase.ts` | Composables |\n| `camelCase.ts` | Utilities, API clients, types |\n| `kebab-case` directories | Route segments, feature folders |\n\n---\n\n## 2. Component Architecture\n\n### Single-File Component Order\n\n```vue\n\u003Cscript setup lang=\"ts\">\n\u002F\u002F 1. Imports (vue → ecosystem → absolute → relative)\n\u002F\u002F 2. Props & Emits & Slots\n\u002F\u002F 3. Composables\n\u002F\u002F 4. Local state (ref\u002Freactive)\n\u002F\u002F 5. Computed properties\n\u002F\u002F 6. Methods\n\u002F\u002F 7. Watchers\n\u002F\u002F 8. Lifecycle hooks\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003C!-- Template content -->\n\u003C\u002Ftemplate>\n\n\u003Cstyle scoped>\n  \u002F* Scoped styles *\u002F\n\u003C\u002Fstyle>\n```\n\n### Presentational vs Container\n\n- **Container components**: Own data fetching, state, and side effects. Render presentational components.\n- **Presentational components**: Receive props, emit events. No API calls, no store access. Pure rendering.\n\n### Props Best Practices\n\n```ts\n\u002F\u002F Type-based props with defaults\ninterface Props {\n  label: string;\n  variant?: \"primary\" | \"secondary\";\n  disabled?: boolean;\n  items: Item[];\n}\n\nconst props = withDefaults(defineProps\u003CProps>(), {\n  variant: \"primary\",\n  disabled: false,\n});\n```\n\n- Always provide `type`, and `required`\u002F`default` where appropriate.\n- Boolean props: `isXxx`, `hasXxx`, `canXxx`.\n- Never mutate props — emit events instead.\n- For v-model binding, use `defineModel()` (Vue 3.4+) or `modelValue` + `update:modelValue`.\n\n### Events\n\n```ts\nconst emit = defineEmits\u003C{\n  submit: [];\n  \"update:modelValue\": [value: string];\n  select: [id: string, index: number];\n}>();\n```\n\n- Use kebab-case in templates (`@update:model-value`).\n- Use camelCase in script (`emit(\"update:modelValue\", val)`).\n\n---\n\n## 3. Composables (Reusable Logic)\n\n### Structure\n\n```ts\n\u002F\u002F composables\u002FuseDebounce.ts\nexport function useDebounce\u003CT>(value: MaybeRef\u003CT>, delay: number): Ref\u003CT> {\n  const debounced = ref(toValue(value)) as Ref\u003CT>;\n\n  let timer: ReturnType\u003Ctypeof setTimeout>;\n  watch(\n    () => toValue(value),\n    (newVal) => {\n      clearTimeout(timer);\n      timer = setTimeout(() => { debounced.value = newVal; }, delay);\n    }\n  );\n\n  onUnmounted(() => clearTimeout(timer));\n  return readonly(debounced);\n}\n```\n\n### Rules\n\n- Must start with `use` prefix.\n- Return reactive values (`ref`, `computed`, `reactive`), never plain primitives.\n- Accept reactive inputs via `MaybeRef` \u002F `toRef()` \u002F `toValue()`.\n- Clean up side effects in `onUnmounted` or watcher `onCleanup`.\n- No module-scope side effects.\n\n### vs Mixins\n\nComposables replace Vue 2 mixins entirely:\n- **Mixins**: Opaque data flow, source-of-truth collisions, name conflicts.\n- **Composables**: Explicit imports, clear return values, composable and tree-shakable.\n\n---\n\n## 4. State Management\n\n### When to Use What\n\n| Pattern | Use Case |\n|---------|----------|\n| `ref()` \u002F `reactive()` | Local component state |\n| Props + Emits | Parent-child communication |\n| Provide \u002F Inject | Theme, config, plugin API |\n| Pinia store | Global, shared, complex state |\n| Server state composable | API data with caching (wrap `fetch`\u002FTanStack Query) |\n\n### Pinia Setup Store (Preferred)\n\n```ts\n\u002F\u002F stores\u002FuseCartStore.ts\nexport const useCartStore = defineStore(\"cart\", () => {\n  const items = ref\u003CCartItem[]>([]);\n  const isLoading = ref(false);\n\n  const totalPrice = computed(() =>\n    items.value.reduce((sum, i) => sum + i.price * i.quantity, 0)\n  );\n  const itemCount = computed(() =>\n    items.value.reduce((sum, i) => sum + i.quantity, 0)\n  );\n\n  async function addItem(productId: string) {\n    isLoading.value = true;\n    try {\n      const item = await fetchProduct(productId);\n      const existing = items.value.find(i => i.id === item.id);\n      if (existing) existing.quantity++;\n      else items.value.push({ ...item, quantity: 1 });\n    } finally {\n      isLoading.value = false;\n    }\n  }\n\n  return { items, isLoading, totalPrice, itemCount, addItem };\n});\n```\n\n- Use Setup Store syntax (not Options Store).\n- Prefer actions for business-level mutations and `$patch()` for grouped updates.\n- Every async action: handle loading + success + error.\n\n---\n\n## 5. Vue Router\n\n### Route Definitions\n\n```ts\nconst routes = [\n  {\n    path: \"\u002Fusers\u002F:id\",\n    name: \"user-detail\",\n    component: () => import(\"@\u002Fpages\u002FUserDetail.vue\"), \u002F\u002F lazy\n    props: true, \u002F\u002F pass params as props\n    meta: { requiresAuth: true },\n  },\n];\n```\n\n### Navigation Guards\n\n```ts\nrouter.beforeEach((to, from) => {\n  const { isLoggedIn } = useAuthStore();\n  if (to.meta.requiresAuth && !isLoggedIn) {\n    return { name: \"login\", query: { redirect: to.fullPath } };\n  }\n});\n```\n\n### Reactive Route Params\n\nWhen a component stays mounted but route params change:\n\n```ts\nconst route = useRoute();\nconst id = computed(() => route.params.id as string);\nwatch(id, (newId) => fetchItem(newId));\n```\n\n---\n\n## 6. Template Patterns\n\n### Template Syntax\n\n```vue\n\u003C!-- v-if\u002Fv-else-if\u002Fv-else -->\n\u003Cdiv v-if=\"isLoading\">Loading...\u003C\u002Fdiv>\n\u003Cdiv v-else-if=\"error\">Error: {{ error }}\u003C\u002Fdiv>\n\u003Cdiv v-else>{{ content }}\u003C\u002Fdiv>\n\n\u003C!-- v-show for frequent toggles -->\n\u003Cdiv v-show=\"isOpen\">Toggled content\u003C\u002Fdiv>\n\n\u003C!-- v-for with stable keys -->\n\u003Cdiv v-for=\"item in items\" :key=\"item.id\">{{ item.name }}\u003C\u002Fdiv>\n\n\u003C!-- Computed filtered list (not v-if + v-for on same element) -->\n\u003Cdiv v-for=\"item in activeItems\" :key=\"item.id\">{{ item.name }}\u003C\u002Fdiv>\n\n\u003C!-- Event handling -->\n\u003Cform @submit.prevent=\"handleSubmit\">\n  \u003Cbutton type=\"submit\">Save\u003C\u002Fbutton>\n\u003C\u002Fform>\n\n\u003C!-- v-model -->\n\u003Cinput v-model=\"name\" \u002F>\n\u003CCustomInput v-model=\"value\" v-model:title=\"title\" \u002F>\n```\n\n---\n\n## 7. Performance\n\n| Technique | When to Use |\n|-----------|-------------|\n| `v-memo` | List items that rarely change |\n| `v-once` | Content rendered once and static forever |\n| `shallowRef()` | Large data structures replaced wholesale |\n| `shallowReactive()` | Only top-level properties are reactive |\n| `v-show` over `v-if` | Frequent visibility toggles |\n| `\u003CKeepAlive :max=\"10\">` | Cache toggled views |\n| Lazy routes | `() => import(...)` for non-critical routes |\n| `Suspense` | Async component loading with fallback |\n\n---\n\n## 8. Testing\n\n### Stack\n\n- **Vitest** for unit and component tests\n- **Vue Test Utils** for mounting and interaction\n- **@pinia\u002Ftesting** for store mocking\n- **Playwright** for E2E\n\n### Component Test Pattern\n\n```ts\nimport { mount } from \"@vue\u002Ftest-utils\";\nimport { createPinia, setActivePinia } from \"pinia\";\nimport UserCard from \".\u002FUserCard.vue\";\n\nbeforeEach(() => { setActivePinia(createPinia()); });\n\nit(\"renders and emits\", async () => {\n  const wrapper = mount(UserCard, {\n    props: { user: { id: \"1\", name: \"Alice\" } },\n  });\n  expect(wrapper.text()).toContain(\"Alice\");\n  await wrapper.find(\"button\").trigger(\"click\");\n  expect(wrapper.emitted(\"select\")![0]).toEqual([\"1\"]);\n});\n```\n\n---\n\n## 9. Nuxt-Specific Patterns\n\n### Auto-Imports\n\nNuxt auto-imports `ref`, `computed`, `watch`, `useFetch`, `useAsyncData`, etc. Use them directly without importing. For non-Nuxt projects, always import explicitly.\n\n### useAsyncData \u002F useFetch\n\n```ts\nconst { data: user, pending, error, refresh } = await useAsyncData(\n  \"user\", \u002F\u002F unique key for caching\n  () => $fetch(`\u002Fapi\u002Fusers\u002F${id}`),\n);\n\nconst { data: posts } = await useFetch(\"\u002Fapi\u002Fposts\", {\n  query: { page: 1 },\n  key: \"posts-page-1\", \u002F\u002F dedupes requests\n});\n```\n\n### Server Routes\n\n```ts\n\u002F\u002F server\u002Fapi\u002Fusers\u002F[id].ts\nexport default defineEventHandler(async (event) => {\n  const { id } = await getValidatedRouterParams(event, z.object({\n    id: z.string().uuid(),\n  }).parse);\n  \u002F\u002F ... fetch and return\n});\n```\n\n### Runtime Config\n\n```ts\n\u002F\u002F nuxt.config.ts\nexport default defineNuxtConfig({\n  runtimeConfig: {\n    \u002F\u002F server-only\n    apiSecret: \"\",\n    \u002F\u002F public (exposed to client)\n    public: {\n      apiBase: \"https:\u002F\u002Fapi.example.com\",\n    },\n  },\n});\n```\n\n---\n\n## 10. Vue 3.5+ New APIs\n\n### Reactive Props Destructure\n\nVue 3.5 stabilized reactive props destructure — destructured variables from `defineProps()` are automatically reactive:\n\n```ts\n\u002F\u002F Vue 3.5+: destructured props are reactive (no need for toRefs)\nconst { count = 0, msg = \"hello\" } = defineProps\u003C{\n  count?: number;\n  msg?: string;\n}>();\n\n\u002F\u002F Limitation: cannot watch destructured prop directly\nwatch(() => count, (newVal) => { ... }); \u002F\u002F PASS getter required\n```\n\n### `useTemplateRef()`\n\nReplace name-matched plain refs with `useTemplateRef()` for template references:\n\n```ts\nimport { useTemplateRef } from \"vue\";\nconst inputEl = useTemplateRef\u003CHTMLInputElement>(\"input\");\n\u002F\u002F \"input\" matches the ref=\"input\" attribute in template, not the variable name\n```\n\nSupports dynamic ref IDs: `useTemplateRef(dynamicRefId)`.\n\n### `onWatcherCleanup()`\n\nGlobally importable watcher cleanup API (Vue 3.5+). It must be called synchronously inside the watcher callback:\n\n```ts\nimport { watch, onWatcherCleanup } from \"vue\";\n\nwatch(userId, async (newId) => {\n  const controller = new AbortController();\n  onWatcherCleanup(() => controller.abort());\n  \u002F\u002F ... fetch with signal\n});\n```\n\n### `useId()`\n\nSSR-stable unique ID generation for form elements and accessibility:\n\n```ts\nimport { useId } from \"vue\";\nconst id = useId();\n```\n\n### `defer` Teleport\n\n`\u003CTeleport defer>` allows teleporting to targets rendered in the same cycle:\n\n```vue\n\u003CTeleport defer to=\"#container\">Content\u003C\u002FTeleport>\n\u003Cdiv id=\"container\">\u003C\u002Fdiv>\n```\n\n### Lazy Hydration (SSR)\n\n`defineAsyncComponent()` now supports `hydrate` strategy:\n\n```ts\nimport { defineAsyncComponent, hydrateOnVisible } from \"vue\";\nconst AsyncComp = defineAsyncComponent({\n  loader: () => import(\".\u002FComp.vue\"),\n  hydrate: hydrateOnVisible(),\n});\n```\n\n---\n\n## Anti-Patterns\n\n| Anti-Pattern | Why It's Wrong | The Fix |\n|-------------|---------------|---------|\n| Destructuring `defineProps()` (Vue \u003C 3.5) | Captures snapshot, loses reactivity | Access via `props.xxx` or use `toRefs()` |\n| `watch()` on destructured prop (Vue 3.5+) | Compile-time error — destructured props can't be watched directly | Use getter wrapper: `watch(() => count, ...)` |\n| `v-if` + `v-for` on same element | Ambiguous execution order | Use computed filtered array |\n| `v-for` key = index | Broken state on reorder | Use stable database IDs |\n| Mutating props | Violates one-way data flow | Emit events or use `v-model` |\n| `v-html` with user content | XSS vulnerability | Sanitize with DOMPurify |\n| Mixins in Vue 3 | Opaque, collision-prone | Replace with composables |\n| Module-scope side effects in composable | Shared across instances | Scope in `onMounted` + `onUnmounted` |\n| `reactive()` for replaceable state | Replacement breaks reactivity | Use `ref()` instead |\n| Watcher without cleanup | Memory leaks, race conditions | Use `onCleanup` or `onWatcherCleanup()` (Vue 3.5+) |\n| Options API in new Vue 3 code | Ecosystem move to Composition API | Use `\u003Cscript setup>` |\n| Plain ref for template references | No dynamic ref support, name-matching fragile | Use `useTemplateRef()` (Vue 3.5+) |\n\n## Related Skills\n\n- `accessibility` — ARIA, semantic HTML, focus management\n- `frontend-patterns` — Cross-framework frontend architecture\n- `typescript` — TypeScript best practices applied to Vue projects\n- `coding-standards` — General code quality standards\n",{"name":5,"origin":54,"description":7},"ECC","main","74715deacdc69119d739f38916f8ee4f0f979ebf","skills\u002Fstorage\u002Faffaan-m_ECC\u002Fvue-patterns",0,"https:\u002F\u002Fgithub.com\u002Fmdnaimul22\u002Fhuman-skills","https:\u002F\u002Fgithub.com\u002Fmdnaimul22","AI Agents Workflows Automation | Specializing in Python, FastAPI, MCP Agents & Custom ERP.","2026-11-11 21:16:57",{"source":8,"skillName":5,"commands":64,"prompt":74,"zipAvailable":75},[65,68,71],{"tool":66,"command":67},"npx","npx skills add mdnaimul22\u002Fhuman-skills --skill vue-patterns",{"tool":69,"command":70},"bunx","bunx skills add mdnaimul22\u002Fhuman-skills --skill vue-patterns",{"tool":72,"command":73},"pnpm","pnpm dlx skills add mdnaimul22\u002Fhuman-skills --skill vue-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmdnaimul22\u002Fhuman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstorage\u002Faffaan-m_ECC\u002Fvue-patterns\u002FSKILL.md",true,[],[78,86,94,101,108,115],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":85},"01M767791C1KRP2ZRW2Z73VZ5Q","system-lifecycle-designer","Universal architectural methodology for designing granular, atomic, and sub-atomic lifecycles and end-to-end workflows for single functionality integrations across any domain (daemons, batch jobs, request transactions, resource pools). Provides patterns for deterministic identity, pre-commit validation, differential reconciliation, sticky leasing, state machines, transactional persistence, and closed-loop feedback.","https:\u002F\u002Fgithub.com\u002Fmdnaimul22\u002Fhuman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstorage\u002Fmy_skills\u002Fsystem-lifecycle-designer\u002FSKILL.md",[],[],"2026-11-12 13:55:43",{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":93},"01M748ABPN5F1FANHH6HKZQMXT","style-sampling","Make a new episode in a proven video style - Collage Explainer, Finance Explainer, Animated Science Explainer, 3D Brand Explainer, 3D True Crime - on the person's topic. Use for \"an episode of\", \"in the style of\", \"sample this style\", 「用这个风格做一集」. One video to copy is reverse-any-video.","https:\u002F\u002Fgithub.com\u002Fmdnaimul22\u002Fhuman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstorage\u002Fheygen-com_hyperframes\u002Fstyle-sampling\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":93},"01M748A59V04PKW4HA0XQ81FGP","reverse-any-video","Rebuild any video file as an editable HyperFrames project - motion graphics, talking heads, live action or AI-generated footage - checked against the original frame by frame. Use to reverse, recreate, remake, replicate or copy a video, or 「复刻这个视频」「照着这个视频做一个」.","https:\u002F\u002Fgithub.com\u002Fmdnaimul22\u002Fhuman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstorage\u002Fheygen-com_hyperframes\u002Freverse-any-video\u002FSKILL.md",[],[],{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":93},"01M7487T50P55CSXMWXZ0G9KRG","typescript-patterns","TypeScript patterns for strict, type-safe, maintainable code in modern TypeScript and JavaScript applications. Covers strict compiler configuration, type design, narrowing, discriminated unions, generics, async and error handling, module boundaries, dependency hygiene, and type-level testing. Use when writing or reviewing TypeScript or JavaScript code.","https:\u002F\u002Fgithub.com\u002Fmdnaimul22\u002Fhuman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstorage\u002Faffaan-m_ECC\u002Ftypescript-patterns\u002FSKILL.md",[],[],{"skillNo":109,"name":110,"nameZh":6,"description":111,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":93},"01M7487ERZRGPC5NJ75077Y238","test-collaboration","Inventory and govern a project's test assets. Connect requirements, business rules, risks, bugs, and cross-boundary contracts to stable TEST-IDs and executable evidence in the repository's existing test registry or TESTS.md. Use for test inventory, test gap analysis, unit\u002Fintegration\u002Fcontract\u002FE2E\u002Fsmoke classification, bug-to-test regression protection, consumer\u002Fprovider contract testing, test-necessity review, and pre-delivery evidence review.","https:\u002F\u002Fgithub.com\u002Fmdnaimul22\u002Fhuman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstorage\u002Faffaan-m_ECC\u002Ftest-collaboration\u002FSKILL.md",[],[],{"skillNo":116,"name":117,"nameZh":6,"description":118,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":119,"categories":120,"keywords":121,"publishedAt":93},"01M748721J3GKR2WS6K0QWFC35","story-lifecycle","Manage a file-based epic → story → sprint development loop without requiring an external project management tool. Creates and tracks epics, breaks them into user stories, assigns them to sprints, and drives implementation story by story. Use when starting a new feature initiative or when the team has no Jira\u002FLinear\u002FTaiga but needs structured delivery tracking.","https:\u002F\u002Fgithub.com\u002Fmdnaimul22\u002Fhuman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstorage\u002Faffaan-m_ECC\u002Fstory-lifecycle\u002FSKILL.md",[],[]]