vue-best-practices
Installation
SKILL.md
Vue Best Practices
Use this skill for Vue applications and component libraries. Project instructions and established public contracts take precedence over this skill's style defaults.
Core Defaults
- Use Vue 3, Composition API, and
<script setup lang="ts">unless nearby code clearly uses another style. - This skill's style default is
<script>(including<script setup lang="ts">), then<template>, then<style>. This is a maintained preference, not a Vue requirement; follow explicit project or user instructions when they differ. - Follow nearby component, package, and test conventions before introducing a new pattern.
- Check the installed Vue version: reactive props destructuring is enabled by default in 3.5+,
defineModelis stable in 3.4+, and getter-basedtoRef,defineSlots, and named-tuple emits require 3.3+. - In Vue 3.5+, prefer
useTemplateRef('name')for static template refs matchingref="name"; add a generic when type inference needs help. KeeprefandshallowReffor reactive state or older Vue versions. - In Vue 3.5+, prefer reactive prop destructuring in
<script setup>when it matches local style; passtoRef(() => prop)to composables expecting a ref. In earlier versions, retainprops.fooor use a compatible prop ref. - Prefer
v-model:propplusdefineModelfor true two-way component contracts; use props plus emits for ordinary parent-owned updates. - Keep source state minimal, derive with
computed, and usewatchfor side effects. - Prefer typed
defineProps,defineEmits,defineSlots, anddefineModel. - Keep components focused. Extract pure logic into utilities/helpers; extract local composables when Vue reactivity, side effects, lifecycle hooks, or orchestration make a component hard to scan.