onBeforeMount()

Registers a callback run right before the component is mounted.

Since Vue 3.0 Spec ↗

Syntax

onBeforeMount(callback): void

Parameters

NameTypeRequiredDescription
callback () => void No Function run after setup but before first render.

Returns

void — Nothing; registers the hook.

Examples

<script setup lang="ts">
import { onBeforeMount } from 'vue';

onBeforeMount(() => {
  console.log('about to render; DOM not yet created');
});
</script>

Notes

Called after reactive state is set up but before the initial DOM render, so template refs and the component DOM are not yet available. Rarely needed in Composition API since setup itself runs before mount; prefer onMounted for DOM work.