Vue
Based on Vue 3.5. Always use Composition API with <script setup lang="ts">.
Preferences
- Prefer TypeScript over JavaScript
- Prefer
<script setup lang="ts"> over <script>
- For performance, prefer
shallowRef over ref if deep reactivity is not needed
- Always use Composition API over Options API
- Discourage using Reactive Props Destructure
Core
| Topic |
Description |
Reference |
| Script Setup & Macros |
<script setup>, defineProps, defineEmits, defineModel, defineExpose, defineOptions, defineSlots, generics |
script-setup-macros |
| Reactivity & Lifecycle |
ref, shallowRef, computed, watch, watchEffect, effectScope, lifecycle hooks, composables |
core-new-apis |
Features
| Topic |
Description |
Reference |
| Built-in Components & Directives |
Transition, Teleport, Suspense, KeepAlive, v-memo, custom directives |
advanced-patterns |
Quick Reference
Component Template
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'
const props = defineProps<{
title: string
count?: number
}>()
const emit = defineEmits<{
update: [value: string]
}>()
const model = defineModel<string>()
const doubled = computed(() => (props.count ?? 0) * 2)
watch(() => props.title, (newVal) => {
console.log('Title changed:', newVal)
})
onMounted(() => {
console.log('Component mounted')
})
</script>
<template>
<div>{{ title }} - {{ doubled }}</div>
</template>
Key Imports
// Reactivity
import { computed, reactive, readonly, ref, shallowRef, toRef, toRefs, toValue } from 'vue'
// Watchers
import { onWatcherCleanup, watch, watchEffect, watchPostEffect } from 'vue'
// Lifecycle
import { onBeforeMount, onBeforeUnmount, onBeforeUpdate, onMounted, onUnmounted, onUpdated } from 'vue'
// Utilities
import { defineAsyncComponent, defineComponent, nextTick } from 'vue'
1---2name: vue3description: 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.4---56# Vue78> Based on Vue 3.5. Always use Composition API with `<script setup lang="ts">`.910## Preferences1112- Prefer TypeScript over JavaScript13- Prefer `<script setup lang="ts">` over `<script>`14- For performance, prefer `shallowRef` over `ref` if deep reactivity is not needed15- Always use Composition API over Options API16- Discourage using Reactive Props Destructure1718## Core1920| Topic | Description | Reference |21|-------|-------------|-----------|22| Script Setup & Macros | `<script setup>`, defineProps, defineEmits, defineModel, defineExpose, defineOptions, defineSlots, generics | [script-setup-macros](references/script-setup-macros.md) |23| Reactivity & Lifecycle | ref, shallowRef, computed, watch, watchEffect, effectScope, lifecycle hooks, composables | [core-new-apis](references/core-new-apis.md) |2425## Features2627| Topic | Description | Reference |28|-------|-------------|-----------|29| Built-in Components & Directives | Transition, Teleport, Suspense, KeepAlive, v-memo, custom directives | [advanced-patterns](references/advanced-patterns.md) |3031## Quick Reference3233### Component Template3435```vue36<script setup lang="ts">37import { computed, onMounted, ref, watch } from 'vue'3839const props = defineProps<{40 title: string41 count?: number42}>()4344const emit = defineEmits<{45 update: [value: string]46}>()4748const model = defineModel<string>()4950const doubled = computed(() => (props.count ?? 0) * 2)5152watch(() => props.title, (newVal) => {53 console.log('Title changed:', newVal)54})5556onMounted(() => {57 console.log('Component mounted')58})59</script>6061<template>62 <div>{{ title }} - {{ doubled }}</div>63</template>64```6566### Key Imports6768```ts69// Reactivity70import { computed, reactive, readonly, ref, shallowRef, toRef, toRefs, toValue } from 'vue'7172// Watchers73import { onWatcherCleanup, watch, watchEffect, watchPostEffect } from 'vue'7475// Lifecycle76import { onBeforeMount, onBeforeUnmount, onBeforeUpdate, onMounted, onUnmounted, onUpdated } from 'vue'7778// Utilities79import { defineAsyncComponent, defineComponent, nextTick } from 'vue'80```