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>
