Skip to content
Vue 3

vue (Composition API) API Reference

Vue 3 core APIs — reactivity primitives, component definition, and the composables convention.

By EZ4Code Team

Reactivity

Reactivity APIs: ref, reactive, computed, watch, and watchEffect for managing reactive state.

ref<T>(value) -> Ref<T>

Creates a reactive reference wrapping a primitive or object; access the value via .value.

Returns: Ref<T>

reactive<T>(obj) -> UnwrapNestedRefs<T>

Returns a reactive proxy of an object; nested properties are also reactive. Do not replace the whole object.

Returns: UnwrapNestedRefs<T>

computed<T>(getter) -> ComputedRef<T>

Creates a read-only computed ref whose value is derived from reactive sources and cached until dependencies change.

Returns: ComputedRef<T>

watch(source, callback, options?)

Watches one or more reactive sources and runs a callback when they change, receiving new and old values.

Returns: StopHandle

watchEffect(effect) -> StopHandle

Runs an effect immediately and re-runs it whenever its reactive dependencies change. Tracks deps automatically.

Returns: StopHandle

Component

Component definition APIs: defineComponent, defineProps, defineEmits, and lifecycle hooks.

defineComponent(options) -> Component

Defines a component with full type inference for Options API or pre-typed components.

Returns: Component

defineProps<T>() / defineProps(arrayOrObject)

Compile-time macro inside <script setup> declaring component props with full type inference.

Returns: Props object

defineEmits<T>() / defineEmits(arrayOrObject)

Compile-time macro declaring events a component can emit.

Returns: Emit function

onMounted(callback)

Lifecycle hook called after the component has been mounted to the DOM.

Returns: void

Composables

Convention for encapsulating reusable reactive logic as functions prefixed with 'use'.

useXxx(...args) -> { state, methods }

A user-defined composable that wraps reactive state and exposes it. By convention names start with 'use'.

Returns: object

useSlots() -> Slots

Returns the component's slots object for programmatic slot access in setup.

Returns: Slots

useAttrs() -> Record<string, unknown>

Returns the component's fallthrough attributes (non-prop, non-emit) for programmatic access.

Returns: Record<string, unknown>

More Vue 3 API References