Lifecycle hooks jippermettulek tħadded kodiċi f'mumenti speċifiċi fil-ħajja ta' komponent — ħoloq, mounting għad-DOM, aġġornament, u tneħħija. Fil-Composition API huma funzjonijiet li tistoħħoġ fi ħdan setup.
Il-hooks ewlenin fl-ordni
<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>
