Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Enforces Vue 3 Composition API best practices with script setup, TypeScript, Pinia, and Vite.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: vue-best-practices3description: MUST be used for Vue.js tasks. Strongly recommends Composition API with `<script setup>` and TypeScript as the standard approach. Covers Vue 3, SSR, Volar, vue-tsc. Load for any Vue, .vue files, Vue Router, Pinia, or Vite with Vue work. ALWAYS use Composition API unless the project explicitly requires Options API.4license: MIT5metadata:6author: github.com/vuejs-ai7version: "18.0.0"8---910# Vue Best Practices Workflow1112Use this skill as an instruction set. Follow the workflow in order unless the user explicitly asks for a different order.1314## Core Principles15- **Keep state predictable:** one source of truth, derive everything else.16- **Make data flow explicit:** Props down, Events up for most cases.17- **Favor small, focused components:** easier to test, reuse, and maintain.18- **Avoid unnecessary re-renders:** use computed properties and watchers wisely.19- **Readability counts:** write clear, self-documenting code.2021## 1) Confirm architecture before coding (required)2223- Default stack: Vue 3 + Composition API + `<script setup lang="ts">`.24- If the project explicitly uses Options API, load `vue-options-api-best-practices` skill if available.25- If the project explicitly uses JSX, load `vue-jsx-best-practices` skill if available.2627### 1.1 Must-read core references (required)2829- Before implementing any Vue task, make sure to read and apply these core references:30- `references/reactivity.md`31- `references/sfc.md`32- `references/component-data-flow.md`33- `references/composables.md`34- Keep these references in active working context for the entire task, not only when a specific issue appears.3536### 1.2 Plan component boundaries before coding (required)3738Create a brief component map before implementation for any non-trivial feature.3940- Define each component's single responsibility in one sentence.41- Keep entry/root and route-level view components as composition surfaces by default.42- Move feature UI and feature logic out of entry/root/view components unless the task is intentionally a tiny single-file demo.43- Define props/emits contracts for each child component in the map.44- Prefer a feature folder layout (`components/<feature>/...`, `composables/use<Feature>.ts`) when adding more than one component.4546## 2) Apply essential Vue foundations (required)4748These are essential, must-know foundations. Apply all of them in every Vue task using the core references already loaded in section `1.1`.4950### Reactivity5152- Must-read reference from `1.1`: [reactivity](references/reactivity.md)53- Keep source state minimal (`ref`/`reactive`), derive everything possible with `computed`.54- Use watchers for side effects if needed.55- Avoid recomputing expensive logic in templates.5657### SFC structure and template safety5859- Must-read reference from `1.1`: [sfc](references/sfc.md)60- Keep SFC sections in this order: `<script>` → `<template>` → `<style>`.61- Keep SFC responsibilities focused; split large components.62- Keep templates declarative; move branching/derivation to script.63- Apply Vue template safety rules (`v-html`, list rendering, conditional rendering choices).6465### Keep components focused6667Split a component when it has **more than one clear responsibility** (e.g. data orchestration + UI, or multiple independent UI sections).6869- Prefer **smaller components + composables** over one “mega component”70- Move **UI sections** into child components (props in, events out).71- Move **state/side effects** into composables (`useXxx()`).7273Apply objective split triggers. Split the component if **any** condition is true:7475- It owns both orchestration/state and substantial presentational markup for multiple sections.76- It has 3+ distinct UI sections (for example: form, filters, list, footer/status).77- A template block is repeated or could become reusable (item rows, cards, list entries).7879Entry/root and route view rule:8081- Keep entry/root and route view components thin: app shell/layout, provider wiring, and feature composition.82- Do not place full feature implementations in entry/root/view components when those features contain independent parts.83- For CRUD/list features (todo, table, catalog, inbox), split at least into:84- feature container component85- input/form component86- list (and/or item) component87- footer/actions or filter/status component88- Allow a single-file implementation only for very small throwaway demos; if chosen, explicitly justify why splitting is unnecessary.8990### Component data flow9192- Must-read reference from `1.1`: [component-data-flow](references/component-data-flow.md)93- Use props down, events up as the primary model.94- Use `v-model` only for true two-way component contracts.95- Use provide/inject only for deep-tree dependencies or shared context.96- Keep contracts explicit and typed with `defineProps`, `defineEmits`, and `InjectionKey` as needed.9798### Composables99100- Must-read reference from `1.1`: [composables](references/composables.md)101- Extract logic into composables when it is reused, stateful, or side-effect heavy.102- Keep composable APIs small, typed, and predictable.103- Separate feature logic from presentational components.104105## 3) Consider optional features only when requirements call for them106107### 3.1 Standard optional features108109Do not add these by default. Load the matching reference only when the requirement exists.110111- Slots: parent needs to control child content/layout -> [component-slots](references/component-slots.md)112- Fallthrough attributes: wrapper/base components must forward attrs/events safely -> [component-fallthrough-attrs](references/component-fallthrough-attrs.md)113- Built-in component `<KeepAlive>` for stateful view caching -> [component-keep-alive](references/component-keep-alive.md)114- Built-in component `<Teleport>` for overlays/portals -> [component-teleport](references/component-teleport.md)115- Built-in component `<Suspense>` for async subtree fallback boundaries -> [component-suspense](references/component-suspense.md)116- Animation-related features: pick the simplest approach that matches the required motion behavior.117- Built-in component `<Transition>` for enter/leave effects -> [transition](references/component-transition.md)118- Built-in component `<TransitionGroup>` for animated list mutations -> [transition-group](references/component-transition-group.md)119- Class-based animation for non-enter/leave effects -> [animation-class-based-technique](references/animation-class-based-technique.md)120- State-driven animation for user-input-driven animation -> [animation-state-driven-technique](references/animation-state-driven-technique.md)121122### 3.2 Less-common optional features123124Use these only when there is explicit product or technical need.125126- Directives: behavior is DOM-specific and not a good composable/component fit -> [directives](references/directives.md)127- Async components: heavy/rarely-used UI should be lazy loaded -> [component-async](references/component-async.md)128- Render functions only when templates cannot express the requirement -> [render-functions](references/render-functions.md)129- Plugins when behavior must be installed app-wide -> [plugins](references/plugins.md)130- State management patterns: app-wide shared state crosses feature boundaries -> [state-management](references/state-management.md)131132## 4) Run performance optimization after behavior is correct133134Performance work is a post-functionality pass. Do not optimize before core behavior is implemented and verified.135136- Large list rendering bottlenecks -> [perf-virtualize-large-lists](references/perf-virtualize-large-lists.md)137- Static subtrees re-rendering unnecessarily -> [perf-v-once-v-memo-directives](references/perf-v-once-v-memo-directives.md)138- Over-abstraction in hot list paths -> [perf-avoid-component-abstraction-in-lists](references/perf-avoid-component-abstraction-in-lists.md)139- Expensive updates triggered too often -> [updated-hook-performance](references/updated-hook-performance.md)140141## 5) Final self-check before finishing142143- Core behavior works and matches requirements.144- All must-read references were read and applied.145- Reactivity model is minimal and predictable.146- SFC structure and template rules are followed.147- Components are focused and well-factored, splitting when needed.148- Entry/root and route view components remain composition surfaces unless there is an explicit small-demo exception.149- Component split decisions are explicit and defensible (responsibility boundaries are clear).150- Data flow contracts are explicit and typed.151- Composables are used where reuse/complexity justifies them.152- Moved state/side effects into composables if applicable153- Optional features are used only when requirements demand them.154- Performance changes were applied only after functionality was complete.155