Skip to main content

Vue.js Reference

v1.0.0

Quick reference for Vue.js 3 Composition API, directives, and reactivity

Vue.js 3 quick-reference covering template directives, Composition API, reactivity, lifecycle hooks, components, Vue Router, Pinia, and utility functions. Search and filter entries by name or category.

How to use
  • Type in the search box to filter entries by name, syntax, or description.
  • Click a category chip to narrow results — click again to clear the filter.
  • Expand any entry to see a syntax snippet and a practical code example.
  • Use the example picker for preset filter scenarios.

44 entries found

v-bind
Template Directives

v-bind:attr="expr" or :attr="expr"

Dynamically bind an attribute or prop to an expression.

v-model
Template Directives

v-model="ref"

Two-way binding on form inputs, textareas, and custom components.

v-if / v-else-if / v-else
Template Directives

v-if="cond" v-else-if="cond" v-else

Conditionally render elements. Removes/adds DOM nodes.

v-show
Template Directives

v-show="expr"

Toggle visibility via CSS display — element stays in DOM.

v-for
Template Directives

v-for="(item, idx) in list" :key="item.id"

Render a list of items. Always provide a unique :key.

v-on
Template Directives

v-on:event="handler" or @event="handler"

Attach an event listener. Supports modifiers like .prevent, .stop, .once.

v-slot
Template Directives

v-slot:name or #name

Define named and scoped slots for child component content.

v-html / v-text
Template Directives

v-html="rawHtml" v-text="str"

Set inner HTML or text content. v-html can cause XSS — sanitize input.

setup()
Composition API

<script setup> or setup() { return {} }

Entry point for Composition API logic. script setup is the recommended form.

ref()
Composition API

const x = ref(initialValue)

Create a reactive reference. Access value via .value in script, auto-unwrapped in templates.

reactive()
Composition API

const state = reactive({ key: value })

Create a deeply reactive object. No .value needed but cannot reassign the object itself.

computed()
Composition API

const val = computed(() => expr)

Cached derived value that auto-updates when dependencies change.

watch()
Composition API

watch(source, (newVal, oldVal) => { })

Run a side effect when a reactive source changes.

watchEffect()
Composition API

watchEffect(() => { /* uses reactive deps */ })

Immediately runs a function and re-runs it whenever its reactive dependencies change.

toRef()
Reactivity

const r = toRef(reactiveObj, 'key')

Create a ref that is linked to a property of a reactive object.

toRefs()
Reactivity

const { a, b } = toRefs(reactiveObj)

Convert all properties of a reactive object to individual refs. Useful for destructuring.

shallowRef()
Reactivity

const x = shallowRef(value)

Like ref but only the .value replacement is reactive — nested mutations are not tracked.

readonly()
Reactivity

const ro = readonly(reactiveObj)

Create a read-only proxy of a reactive object. Mutations are rejected with a warning.

unref()
Reactivity

const val = unref(maybeRef)

Returns .value if the argument is a ref, otherwise returns the argument as-is.

isRef() / isReactive()
Reactivity

isRef(val) / isReactive(val)

Type guards to check whether a value is a ref or reactive object.

onMounted()
Lifecycle Hooks

onMounted(() => { })

Called after the component is mounted to the DOM. Safe to access DOM elements.

onUnmounted()
Lifecycle Hooks

onUnmounted(() => { })

Called when the component is about to be destroyed. Clean up timers, listeners, subscriptions.

onUpdated()
Lifecycle Hooks

onUpdated(() => { })

Called after a reactive state change causes the component to re-render.

onBeforeMount()
Lifecycle Hooks

onBeforeMount(() => { })

Called right before the component is mounted. DOM is not available yet.

onErrorCaptured()
Lifecycle Hooks

onErrorCaptured((err, instance, info) => { })

Called when an error from a descendant component is captured. Return false to stop propagation.

defineProps()
Components

const props = defineProps<{ name: string }>()

Declare component props with TypeScript types. Compile-time only — no import needed in script setup.

defineEmits()
Components

const emit = defineEmits<{ (e: 'update', val: number): void }>()

Declare custom events the component can emit.

defineExpose()
Components

defineExpose({ method, ref })

Explicitly expose public properties for parent template ref access.

provide() / inject()
Components

provide(key, value) / const val = inject(key)

Dependency injection across component tree — avoids prop drilling.

Suspense
Components

<Suspense> <template #default> ... </Suspense>

Display a fallback while async child components resolve.

Teleport
Components

<Teleport to="#target">...</Teleport>

Render child content at a different DOM location (e.g. modals to body).

createRouter()
Vue Router

createRouter({ history, routes })

Create a Vue Router instance with history mode and route definitions.

useRouter() / useRoute()
Vue Router

const router = useRouter() const route = useRoute()

Access the router instance and current route in Composition API.

RouterView / RouterLink
Vue Router

<RouterView /> <RouterLink to="/path">

Render the matched route component and create navigation links.

Navigation Guards
Vue Router

router.beforeEach((to, from) => { })

Global guards that run before each navigation. Return false or a route to redirect.

Route meta
Vue Router

{ path: '/', meta: { requiresAuth: true } }

Attach custom metadata to routes — accessible via route.meta.

defineStore()
Pinia Store

defineStore('id', () => { })

Define a Pinia store using the Composition API syntax (setup stores).

storeToRefs()
Pinia Store

const { prop } = storeToRefs(store)

Destructure store properties while keeping reactivity. Methods can be destructured directly.

$patch()
Pinia Store

store.$patch({ key: value }) or store.$patch(state => { })

Batch-update multiple store state properties in a single mutation.

$reset()
Pinia Store

store.$reset()

Reset the store state to its initial value (option stores only).

nextTick()
Utilities

await nextTick()

Wait for the next DOM update flush. Useful when reading DOM after a state change.

defineAsyncComponent()
Utilities

defineAsyncComponent(() => import('./Comp.vue'))

Lazy-load a component — only fetched when first rendered.

h() render function
Utilities

h(tag, props, children)

Programmatically create vnodes — the JSX/hyperscript alternative to templates.

useTemplateRef()
Utilities

const el = useTemplateRef('name')

Type-safe template ref access (Vue 3.5+). Replaces the ref() + template ref pattern.