Lifecycle hooks అనేవి ఒక కాంపోనెంట్ యొక్క జీవితంలో నిర్దిష్ట నిమిషాలలో కోడ్ను అమలు చేయడానికి మిమ్మల్ని అనుమతించే ఫంక్షన్లు — సృష్టి, DOM కు రుద్ది, నవీకరణ మరియు తొలగింపు. Composition API లో అవి setup లో కాల్ చేసే ఫంక్షన్లు.
క్రమంలో ప్రధాన hooks
<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>
