Index of every page on this site: llms.txt
All skills
antfu avatar

/vue

@7de210b official
by Anthony Fuantfu/skills6k stars
342
Run it yourself

Vue 3 Composition API, script setup macros, reactivity system, and built-in components. Use when writing Vue SFCs, defineProps/defineEmits/defineModel, watchers, or using Transition/Teleport/Suspense/KeepAlive.

Use this Skill: https://skilld.dev/gh/antfu/skills/vue

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesscript-setup-macros.md

≈1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Script Setup & Macros

<script setup> is the recommended syntax for Vue SFCs with Composition API. It provides better runtime performance and IDE type inference.

Basic Syntax

<script setup lang="ts">
// Top-level bindings are exposed to template
import { ref } from 'vue'
import MyComponent from './MyComponent.vue'

const count = ref(0)
const increment = () => count.value++
</script>

<template>
  <button @click="increment">{{ count }}</button>
  <MyComponent />
</template>

defineProps

Declare component props with full TypeScript support.

// Type-based declaration (recommended)
const props = defineProps<{
  title: string
  count?: number
  items: string[]
}>()

// Imported/aliased interfaces are supported (relative import, path alias like
// @/types, or a node_modules dependency). Requires TypeScript as a peer dep.
import type { Props } from './types'
const props = defineProps<Props>()

// With defaults (Vue 3.5+)
const { title, count = 0 } = defineProps<{
  title: string
  count?: number
}>()

// With defaults (Vue 3.4 and below)
const props = withDefaults(defineProps<{
  title: string
  items?: string[]
}>(), {
  items: () => []  // Use factory for arrays/objects
})

defineEmits

Declare emitted events with typed payloads.

// Named tuple syntax (recommended)
const emit = defineEmits<{
  update: [value: string]
  change: [id: number, name: string]
  close: []
}>()

emit('update', 'new value')
emit('change', 1, 'name')
emit('close')

defineModel

Two-way binding prop consumed via v-model. Available in Vue 3.4+.

// Basic usage - creates "modelValue" prop
const model = defineModel<string>()
model.value = 'hello'  // Emits "update:modelValue"

// Named model - consumed via v-model:name
const count = defineModel<number>('count', { default: 0 })

// With modifiers
const [value, modifiers] = defineModel<string>()
if (modifiers.trim) {
  // Handle trim modifier
}

// With transformers
const [value, modifiers] = defineModel({
  get(val) { return val?.toLowerCase() },
  set(val) { return modifiers.trim ? val?.trim() : val }
})

Parent usage:

<Child v-model="name" />
<Child v-model:count="total" />
<Child v-model.trim="text" />

defineExpose

Explicitly expose properties to parent via template refs. Components are closed by default.

import { ref } from 'vue'

const count = ref(0)
const reset = () => { count.value = 0 }

defineExpose({
  count,
  reset
})

Parent access:

const childRef = ref<{ count: number; reset: () => void }>()
childRef.value?.reset()

defineOptions

Declare component options without a separate <script> block. Available in Vue 3.3+.

defineOptions({
  inheritAttrs: false,
  name: 'CustomName'
})

defineSlots

Provide type hints for slot props. Available in Vue 3.3+.

const slots = defineSlots<{
  default(props: { item: string; index: number }): any
  header(props: { title: string }): any
}>()

Generic Components

Declare generic type parameters using the generic attribute.

<script setup lang="ts" generic="T extends string | number">
defineProps<{
  items: T[]
  selected: T
}>()
</script>

Multiple generics with constraints:

<script setup lang="ts" generic="T, U extends Record<string, T>">
import type { Item } from './types'
defineProps<{
  data: U
  key: keyof U
}>()
</script>

Local Custom Directives

Use vNameOfDirective naming convention.

const vFocus = {
  mounted: (el: HTMLElement) => el.focus()
}

// Or import and rename
import { myDirective as vMyDirective } from './directives'
<template>
  <input v-focus />
</template>

Top-level await

Use await directly in <script setup>. The component becomes async and must be used with <Suspense>.

<script setup lang="ts">
const data = await fetch('/api/data').then(r => r.json())
</script>
<!-- Source references: - https://vuejs.org/api/sfc-script-setup.html -->

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts1mo5 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    The skill provides comprehensive guidelines and references for Vue 3 Composition API and <script setup>. It contains standard code examples and documentation from reputable sources. No security risks were identified.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

  • Runlayer8mo

    1/5 files flagged

  • ZeroLeaks6mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 7de210b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated last month
Other metadata
metadata
{
  "author": "Anthony Fu",
  "version": "2026.9.25",
  "source": "Generated from https://github.com/vuejs/docs, scripts at https://github.com/antfu/skills"
}
  • Vue
  • TypeScript
  • vue3
  • composition-api
  • script-setup
  • reactivity
  • components
  • sfc

README badge

README badge for antfu/skills/vue

Provides Vue 3 Composition API patterns, script setup macros (defineProps, defineEmits, defineModel), reactivity utilities (ref, computed, watch), and built-in components (Transition, Teleport, Suspense, KeepAlive). Use when writing Vue SFCs with TypeScript and <script setup> syntax.

Generated from the current SKILL.md.

Does this skill cover Vue 2 or Vue 3?
This skill is based on Vue 3.5 and uses the Composition API exclusively. It does not cover Vue 2 or the Options API.
Should I use script setup or the traditional script block?
Always use `<script setup lang="ts">`. The skill discourages the traditional `<script>` block in favor of the more concise setup macro syntax.
Does this skill cover advanced patterns like Transition and Suspense?
Yes. The skill includes Vue's built-in components (Transition, Teleport, Suspense, KeepAlive) and directives like v-memo and custom directives.
When should I use shallowRef instead of ref?
Use shallowRef when deep reactivity is not needed, as it offers better performance than ref for large objects or arrays.
Does this skill recommend TypeScript?
Yes. The skill prefers TypeScript over JavaScript and all examples use `lang="ts"`.

Generated from the current SKILL.md. These answers refresh after source changes.