Lifecycle hooks तुम्हाला कंपोनेंटच्या जीवनातील विशिष्ट क्षणी कोड चलवू देतात — तयारी, DOM मध्ये माउंटिंग, अपडेट, आणि काढून टाकणे. Composition API मध्ये हे setup आत कॉल करणारे फंक्शन आहेत.
क्रमात मुख्य hooks
vue
<script setup>
import { onMounted, onUpdated, onUnmounted, ref } from "vue";
const data = ref(null);
onMounted(() => {
// component is now in the DOM — fetch data, access elements, init libraries
fetchData().then(d => (data.value = d));
});
onUpdated(() => {
// runs after the DOM re-renders due to a reactive change
});
onUnmounted(() => {
// component is being removed — CLEAN UP here
clearInterval(timer);
window.removeEventListener("resize", handler);
});
</script>
