---
description: Load Vue component patterns and best practices
---
# Vue Component Priming
> **Note:** This command references the `nuxt:nuxt` skill for progressive disclosure of additional Vue patterns and library-specific documentation.
## Script Setup Syntax
ALWAYS use `
```
### Component Naming
- ALWAYS use multi-word component names except for Nuxt pages and layouts
- Examples: `UserProfile.vue`, `SearchBar.vue` (not `User.vue`, `Search.vue`)
- Exception: `pages/index.vue`, `pages/about.vue`, `layouts/default.vue`
## Template Directives
### v-for Loops
ALWAYS use `key` in v-for loops and prefer `of` over `in`:
```vue
{{ user.name }}
{{ user.name }}
{{ user.name }}
```
### Prop Binding Shorthand
ALWAYS use shorthand syntax when passing props with same name as variable:
```vue
```
## Reactivity and State
### Reactive References
PREFER `ref()` for reactive state instead of `reactive()`:
```typescript
// ✅ Preferred: Using ref
const count = ref(0)
const user = ref({ name: "Alice", age: 30 })
// ❌ Less preferred: Using reactive (loses reactivity on destructure)
const state = reactive({ count: 0 })
```
### Auto-Imported Vue APIs
Never manually import these in Nuxt projects - they're auto-imported:
**Reactivity:**
- `ref` - Reactive primitive values
- `reactive` - Reactive objects
- `computed` - Computed values
- `watch` - Watch reactive values
**Lifecycle:**
- `onMounted` - Component mounted
- `onUnmounted` - Component unmounted
- `onBeforeMount`, `onBeforeUnmount`, etc.
**Component APIs:**
- `defineProps` - Define props (type-based)
- `defineEmits` - Define emits (type-based)
- `defineModel` - Define v-model (type-based)
**Utilities:**
- `useId` - Generate unique IDs for accessibility/form elements (SSR-safe)
## Component Organization
### Logical Grouping
PREFER to group by logical concerns rather than by type:
```typescript
// ✅ Preferred: Grouped by feature/concern
// ❌ Less preferred: Grouped by type
```
## Styling Strategy
**Check `package.json` for `@nuxtjs/tailwindcss`:**
### If Tailwind Installed
```vue
```
### If NO Tailwind
ALWAYS use `
```
## VueUse Composables (If Installed)
Check `package.json` for `@vueuse/core` or `@vueuse/nuxt`:
PREFER VueUse composables over custom implementations for common tasks:
```typescript
// ✅ Preferred: Using VueUse (if installed)
import { useLocalStorage, useMouse, useWindowSize } from "@vueuse/core"
const token = useLocalStorage("auth-token", "")
// ❌ Avoid: Custom implementation when VueUse exists
const token = ref(localStorage.getItem("auth-token") || "")
watch(token, (val) => localStorage.setItem("auth-token", val))
```
### Common VueUse Patterns
**State:**
- `useToggle`, `useCounter`, `useLocalStorage`, `useSessionStorage`
**DOM:**
- `useMouse`, `useScroll`, `useElementVisibility`, `useIntersectionObserver`, `useResizeObserver`
**Browser:**
- `useClipboard`, `useMediaQuery`, `useDark`, `usePreferredDark`, `useGeolocation`
**Utilities:**
- `refDebounced`, `useDebounceFn`, `refThrottled`, `useThrottleFn`, `useInterval`, `useTimeout`
The `nuxt:nuxt` skill provides detailed VueUse reference when installed.
## Accessibility
- Use semantic HTML: `