onBeforeMount()
Registers a callback run right before the component is mounted.
Syntax
onBeforeMount(callback): void Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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.