Lifecycle hooks janë funksione që ju lejojnë të ekzekutoni kod në momente specifike në jetën e një komponente — krijim, montim në DOM, përditësim dhe heqje. Në Composition API ato janë funksione që i thërrisni brenda setup.
Hooks kryesore në rend
<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>
