home / skills / oro-ad / nuxt-claude-devtools / vue-composition-api
This skill helps you implement Vue 3 Composition API patterns in components using script setup, refs, reactive, and computed for robust state management.
npx playbooks add skill oro-ad/nuxt-claude-devtools --skill vue-composition-apiReview the files below or copy the command above to add this skill to your agents.
---
name: vue-composition-api
description: Vue 3 Composition API expert. Use when working with Vue components, composables, or reactive state.
---
You are an expert in Vue 3 Composition API. Apply these patterns:
## Script Setup
Always use `<script setup lang="ts">` syntax for single-file components.
## Reactivity
- Use `ref()` for primitive values
- Use `reactive()` for objects and arrays
- Use `shallowRef()` for large objects that don't need deep reactivity
## Computed Properties
Prefer `computed()` over methods for derived state:
```typescript
const fullName = computed(() => `${firstName.value} ${lastName.value}`)
```
## Watchers
- Use `watch()` for explicit dependencies
- Use `watchEffect()` for automatic dependency tracking
```typescript
watch(source, (newVal, oldVal) => {
// React to changes
})
watchEffect(() => {
// Runs immediately and tracks dependencies
})
```
## Props & Emits
Type with interface syntax:
```typescript
const props = defineProps<{
title: string
count?: number
}>()
const emit = defineEmits<{
(e: 'update', value: string): void
(e: 'close'): void
}>()
```
## Expose
Use `defineExpose()` only when parent components need direct access:
```typescript
defineExpose({
focus,
reset
})
```
## Template Refs
```typescript
const inputRef = ref<HTMLInputElement | null>(null)
onMounted(() => {
inputRef.value?.focus()
})
```
This skill is a Vue 3 Composition API expert focused on practical patterns for single-file components and composables. It enforces TypeScript-driven script setup, predictable reactivity primitives, and clear component APIs. Use it to standardize component structure, improve type safety, and reduce reactivity bugs.
The skill inspects component code and recommends Composition API patterns: script setup with TypeScript, appropriate use of ref, reactive, and shallowRef, plus computed properties and watchers. It also validates prop and emit typing, suggests when to expose methods with defineExpose, and checks template refs and lifecycle usage. Suggestions are concrete snippets and best-practice guidance you can apply directly to files.
When should I use reactive() vs ref()?
Use ref() for primitive values and reactive() for objects or arrays. If you need direct reactivity for top-level properties use reactive(), else use ref for simple values.
When is shallowRef appropriate?
Use shallowRef for large objects or third-party instances where deep reactivity is unnecessary or too expensive; it tracks only the reference, not nested properties.
Should I always use defineExpose()?
No. Only expose methods or properties when a parent must call them. Avoid exposing internals to keep components encapsulated.