Composition API: Lifecycle Hooks | Vue.js
vuejs.org › api › composition-api-lifecycleimport { ref, onserverprefetch, onmounted } from 'vue' const data = ref(null) onserverprefetch(async () => { // component is rendered as part of the initial request // pre-fetch data on server as it is faster than on the client data.value = await fetchonserver(/* ... */) }) onmounted(async () => { if (!data.value) { // if data is null on mount, …
Lifecycle Hooks | Vue.js
vuejs.org › guide › essentialsFor example, the onMounted mounted hook can be used to run code after the component has finished the initial rendering and created the DOM nodes: vue < script setup > import { onMounted } from ' vue ' onMounted ( () => { console . log ( ` the component is now mounted. ` ) } ) </ script >