vue-best-practices
Vue Best Practices
Comprehensive performance optimization guide for Vue.js applications. Contains 40+ rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new Vue components
- Implementing reactive state and computed properties
- Reviewing code for performance issues
- Refactoring existing Vue code
- Optimizing rendering and re-renders
- Working with Composition API or Options API
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Reactivity Fundamentals | CRITICAL | reactivity- |
| 2 | Component Performance | CRITICAL | component- |
| 3 | Computed & Watchers | HIGH | computed- |
| 4 | Template Optimization | MEDIUM-HIGH | template- |
| 5 | Composition API Patterns | MEDIUM | composable- |
| 6 | State Management | MEDIUM | state- |
| 7 | Async & Data Fetching | LOW-MEDIUM | async- |
| 8 | Advanced Patterns | LOW | advanced- |
Quick Reference
1. Reactivity Fundamentals (CRITICAL)
reactivity-ref-vs-reactive- Use ref() for primitives, reactive() for objectsreactivity-avoid-destructure- Don't destructure reactive objectsreactivity-toRefs- Use toRefs() when destructuring is neededreactivity-shallowRef- Use shallowRef() for large non-reactive datareactivity-raw-values- Use toRaw() for read-only operations on large data
2. Component Performance (CRITICAL)
component-v-once- Use v-once for static contentcomponent-v-memo- Use v-memo for expensive list itemscomponent-async- Use defineAsyncComponent for heavy componentscomponent-keep-alive- Cache component state with KeepAlivecomponent-functional- Prefer functional components for stateless UI
3. Computed & Watchers (HIGH)
computed-cache- Use computed() for derived values, not methodscomputed-getter-only- Avoid setters in computed when possiblecomputed-dependencies- Minimize computed dependencieswatch-immediate- Avoid immediate watchers, use computed insteadwatch-deep-avoid- Avoid deep watchers on large objectswatch-cleanup- Always cleanup async watchers
4. Template Optimization (MEDIUM-HIGH)
template-v-show-vs-if- v-show for frequent toggles, v-if for raretemplate-key-attribute- Always use unique keys in v-fortemplate-avoid-v-if-v-for- Never use v-if and v-for on same elementtemplate-static-hoisting- Let compiler hoist static contenttemplate-event-modifiers- Use event modifiers instead of JS handlers
5. Composition API Patterns (MEDIUM)
composable-single-responsibility- One concern per composablecomposable-return-refs- Return refs, not reactive objectscomposable-cleanup- Handle cleanup in composablescomposable-lazy-init- Lazy initialize expensive resourcescomposable-provide-inject- Use provide/inject for deep prop drilling
6. State Management (MEDIUM)
state-pinia-stores- Split stores by domainstate-getters- Use getters for computed statestate-actions-mutations- Keep mutations simple, logic in actionsstate-subscription-cleanup- Cleanup store subscriptions
7. Async & Data Fetching (LOW-MEDIUM)
async-suspense- Use Suspense for async component loadingasync-error-boundaries- Handle async errors gracefullyasync-stale-while-revalidate- Implement SWR pattern for data fetchingasync-abort-controller- Cancel pending requests on unmount
8. Advanced Patterns (LOW)
advanced-custom-directives- Create directives for DOM manipulationadvanced-render-functions- Use render functions for dynamic templatesadvanced-teleport- Use Teleport for modals and overlaysadvanced-transition-groups- Optimize list transitions
How to Use
Read individual rule files for detailed explanations and code examples:
rules/reactivity-ref-vs-reactive.md
rules/component-v-memo.md
rules/_sections.md
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
More from vinayakkulkarni/vue-nuxt-best-practices
nuxt-best-practices
Nuxt 3/4 performance optimization and architecture guidelines for building fast, maintainable full-stack applications. This skill should be used when writing, reviewing, or refactoring Nuxt code to ensure optimal patterns. Triggers on tasks involving data fetching, server routes, auto-imports, rendering modes, or Nuxt-specific features.
107nuxt-seo-best-practices
Nuxt SEO optimization guidelines for Cloudflare-deployed applications. Covers dynamic OG image generation on CF Workers, page SEO composables, JSON-LD structured data, SSR externals, and Nitro configuration. Triggers on tasks involving SEO, meta tags, OG images, Open Graph, Satori, social sharing, or Cloudflare Workers deployment.
13nuxt-geo-best-practices
Nuxt GEO (Generative Engine Optimization) guidelines for getting cited by ChatGPT, Perplexity, Claude, Google AI Overviews, and Gemini. Covers AI crawler access (llms.txt, GPTBot/ClaudeBot/PerplexityBot allowlisting), content extractability for RAG retrieval, entity clarity via JSON-LD, and the evidence-backed +40% visibility levers (statistics, citations, quotations) from the GEO arxiv paper. Triggers on tasks involving GEO, AEO, AI search, LLM visibility, llms.txt, AI crawlers, ChatGPT citations, Perplexity, AI Overviews, generative engines, or AI mentions.
4