Skip to content
vuejs-best-practices logo

Vue.js Best Practices

vuejs-best-practices

Vue 3 and Nuxt 3 performance optimization and best practices. This skill should be used when writing, reviewing, or refactoring Vue.js code to ensure optimal performance patterns. Triggers on tasks involving Vue components, Nuxt pages, Composition API, Pinia state management, or performance impro...

SKILL.md

Full skill instructions

Vue.js Best Practices

Comprehensive performance optimization guide for Vue 3 and Nuxt 3 applications. Contains 50+ rules across 10 categories, prioritized by impact to guide automated refactoring and code generation.

When to Apply

Reference these guidelines when:

  • Writing new Vue 3 components or Nuxt 3 pages
  • Using Composition API and composables
  • Implementing data fetching (client or server-side)
  • Managing state with Pinia
  • Reviewing code for performance issues
  • Refactoring existing Vue/​Nuxt code
  • Optimizing bundle size or load times

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Reactivity OptimizationCRITICALreactivity-
2Bundle Size OptimizationCRITICALbundle-
3Nuxt 3 Server PerformanceHIGHnuxt-
4Component Design PatternsHIGHcomponent-
5Composition API PatternsMEDIUM-HIGHcomposable-
6State Management (Pinia)MEDIUM-HIGHpinia-
7Rendering PerformanceMEDIUMrendering-
8TypeScript IntegrationMEDIUMtypescript-
9Testing PatternsLOW-MEDIUMtesting-
10Advanced PatternsLOWadvanced-

Quick Reference

1. Reactivity Optimization (CRITICAL)

  • reactivity-shallowref - Use shallowRef for large objects that don't need deep reactivity
  • reactivity-shallowreactive - Use shallowReactive for flat objects
  • reactivity-computed-cache - Leverage computed for expensive calculations (auto-caching)
  • reactivity-toraw - Use toRaw() when passing to external libraries
  • reactivity-markraw - Use markRaw() for non-reactive objects (classes, third-party instances)
  • reactivity-effectscope - Use effectScope() to batch cleanup of effects

2. Bundle Size Optimization (CRITICAL)

  • bundle-tree-shaking - Import from 'vue' not internal packages (@vue/​reactivity, @vue/​runtime-core)
  • bundle-async-components - Use defineAsyncComponent for heavy components
  • bundle-dynamic-imports - Dynamic import() for route-level code splitting
  • bundle-icon-imports - Import icons directly, avoid icon libraries barrel files
  • bundle-lodash-es - Use lodash-es with specific imports
  • bundle-analyze - Use rollup-plugin-visualizer to identify bloat
  • bundle-external-cdn - Externalize large libraries to CDN when appropriate

3. Nuxt 3 Server Performance (HIGH)

  • nuxt-usefetch - Use useFetch/​useAsyncData for SSR-friendly data fetching
  • nuxt-lazy-components - Prefix with Lazy for automatic lazy loading
  • nuxt-payload-reduce - Minimize payload with pick/​transform options
  • nuxt-cache-route - Use routeRules for caching strategies
  • nuxt-server-components - Use .server.vue for server-only components
  • nuxt-prerender - Prerender static pages at build time
  • nuxt-islands - Use Nuxt Islands for partial hydration
  • nuxt-nitro-cache - Leverage Nitro caching for API routes

4. Component Design Patterns (HIGH)

  • component-sfc-setup - Always use <script setup> syntax
  • component-props-destructure - Use destructuring with defineProps for reactivity
  • component-emits-typed - Always define emits with TypeScript
  • component-slots-typed - Type slots with defineSlots
  • component-expose - Use defineExpose sparingly, prefer props/​emits
  • component-v-once - Use v-once for static content
  • component-v-memo - Use v-memo for list item optimization
  • component-teleport - Use Teleport for modals/​tooltips

5. Composition API Patterns (MEDIUM-HIGH)

  • composable-naming - Prefix composables with 'use' (useAuth, useFetch)
  • composable-return-object - Return object, not array, for better DX
  • composable-cleanup - Always handle cleanup in onUnmounted
  • composable-async - Handle async state properly (loading, error, data)
  • composable-ssr-safe - Check import.meta.client for browser-only code
  • composable-provide-inject - Use provide/​inject with InjectionKey for type safety
  • composable-vueuse - Leverage VueUse before writing custom composables

6. State Management - Pinia (MEDIUM-HIGH)

  • pinia-setup-syntax - Prefer setup stores over options stores
  • pinia-storetorefs - Use storeToRefs() to maintain reactivity
  • pinia-actions-async - Use actions for async operations, not getters
  • pinia-persist - Use pinia-plugin-persistedstate for persistence
  • pinia-reset - Implement $reset for store cleanup
  • pinia-subscribe - Use $subscribe for side effects
  • pinia-ssr-hydration - Handle SSR hydration properly in Nuxt

7. Rendering Performance (MEDIUM)

  • rendering-v-show-v-if - v-show for frequent toggles, v-if for rare conditions
  • rendering-key-attribute - Always use unique :key in v-for (avoid index as key)
  • rendering-virtual-scroll - Use virtual scrolling for long lists (100+ items)
  • rendering-keep-alive - Cache component instances with KeepAlive
  • rendering-suspense - Use Suspense for async component loading states

8. TypeScript Integration (MEDIUM)

  • typescript-props-interface - Define props with interface, not type
  • typescript-ref-type - Explicitly type refs: ref<string>('')
  • typescript-template-ref - Type template refs: ref<HTMLInputElement | null>(null)
  • typescript-component-type - Use ComponentPublicInstance for component refs
  • typescript-generic-components - Use generic components for reusable patterns
  • typescript-strict-inject - Use InjectionKey<T> for type-safe provide/​inject
  • typescript-event-handlers - Type event handlers properly

9. Testing Patterns (LOW-MEDIUM)

  • testing-vitest - Use Vitest for unit testing (Vue ecosystem native)
  • testing-vue-test-utils - Use @vue/​test-utils for component testing
  • testing-composables - Test composables in isolation
  • testing-pinia - Use createTestingPinia for store testing
  • testing-msw - Use MSW for API mocking
  • testing-playwright - Use Playwright for E2E with Nuxt

10. Advanced Patterns (LOW)

  • advanced-render-function - Use render functions for dynamic component generation
  • advanced-custom-directive - Create custom directives for DOM manipulation
  • advanced-plugin-pattern - Structure plugins with proper install function

Decision Trees

When to use ref vs reactive

What type of data?
│
├── Primitives (string, number, boolean)
│   └── ref() ✓
│
├── Objects/​Arrays (need deep reactivity)
│   └── reactive() ✓
│
├── Large objects (performance critical)
│   └── shallowRef() or shallowReactive() ✓
│
└── Non-reactive data (class instances, external libs)
    └── markRaw() ✓

When to use useFetch vs $fetch (Nuxt)

Where is the code running?
│
├── Component/​Page (need SSR + reactivity)
│   └── useFetch() or useAsyncData() ✓
│
├── Server API route
│   └── $fetch() ✓
│
├── Event handler (client-side only)
│   └── $fetch() ✓
│
└── Composable (reusable)
    └── useFetch() with key ✓

Component communication pattern

What's the relationship?
│
├── Parent → Child
│   └── Props ✓
│
├── Child → Parent
│   └── Emits ✓
│
├── Siblings
│   └── Pinia store or provide/​inject ✓
│
├── Deep nesting (prop drilling)
│   └── provide/​inject ✓
│
└── Global state
    └── Pinia store ✓

Anti-Patterns to Avoid

❌ DON'T:

  • Use Options API in new Vue 3 projects
  • Mutate props directly
  • Use this in <script setup>
  • Create reactive() with primitives
  • Use v-if and v-for on same element
  • Forget :key in v-for loops
  • Use index as :key for dynamic lists
  • Access refs without .value in script
  • Nest Pinia stores unnecessarily
  • Use $fetch in components (use useFetch)

✅ DO:

  • Use Composition API with <script setup>
  • Define props and emits with TypeScript
  • Use computed for derived state
  • Use watchEffect for side effects
  • Leverage VueUse composables
  • Use Pinia for global state
  • Handle loading/​error states
  • Clean up effects in onUnmounted
  • Use Suspense for async components

Performance Checklist

Before shipping:

  • Bundle analyzed? No unexpected large dependencies
  • Lazy loading? Routes and heavy components code-split
  • Reactivity optimized? Using shallowRef where appropriate
  • SSR working? No hydration mismatches
  • Images optimized? Using nuxt/​image or similar
  • API calls deduplicated? Using useFetch with proper keys
  • State management efficient? Not over-fetching in stores
  • List rendering optimized? Virtual scroll for long lists

Full Compiled Document

For detailed code examples, implementation patterns, and comprehensive explanations: AGENTS.md

Each section in AGENTS.md contains:

  • Detailed explanations of why patterns matter
  • Incorrect vs Correct code comparisons
  • Copy-paste ready implementations
  • Vue 3 and Nuxt 3 specific examples
  • VueUse integration examples

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View