Vue 3 Standards
Single-file components
<script setup>with TypeScript for all new components.- Organize: template → script → style (top-down).
- Use scoped styles (
<style scoped>) — never global styles in components. - One component per
.vuefile; PascalCase filename.
Props & events
defineProps<{...}>()anddefineEmits<{...}>()with TypeScript generics.- Use
withDefaultsfor default values. - Props: kebab-case in templates, camelCase in script.
- Prefer props over direct parent access (
$parentis a code smell).
Composition API
reffor primitives;reactivefor objects (or alwaysref— be consistent per project).computedfor derived state — never compute in template expressions.watchonly for side effects (logging, API calls) — not for derived state.- Extract reusable logic into composables (
use<Name>.tsincomposables/).
State management (Pinia)
- One store per domain (
useUserStore,useCartStore). - Actions for async operations and mutations; avoid directly modifying store state outside actions.
- Getters for derived state.
- Keep store logic simple — move business logic to composables or services.
Templates
v-foralways paired with:key(never index as key for dynamic lists).v-ifandv-fornever on the same element — use<template>wrapper.- Event modifiers:
.prevent,.stop,.oncewhere appropriate.
Testing
- Vitest + Vue Test Utils.
mountfor component tests with children;shallowMountfor isolation.- Test behaviour, not implementation details.
Validation commands
vue-tsc --noEmit # typecheck
npm run lint # ESLint + vue plugin
npm run test # Vitest
Source: KhoaNHM/ai-skill-agent — distributed by TomeVault.