ရိုးရိုးလေး ရှင်းပြမယ်
Component တစ်ခု create, mount, update နှင့် unmount အဆင့်များကိုဖြတ်သန်းသည်။ DOM ကိုလိုအပ်သော code ကို onMounted တွင် run ပါ။ Timer, event listener နှင့် subscription များကို onUnmounted တွင်ရှင်းရမည်။
vue
<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
const width = ref(0)
const measure = () => { width.value = window.innerWidth }
onMounted(() => {
measure()
window.addEventListener('resize', measure)
})
onUnmounted(() => window.removeEventListener('resize', measure))
</script>
<template><p>Viewport: {{ width }}px</p></template>You should see
Viewport: 1280pxလက်တွေ့စမ်းကြည့်ရန်
တစ်စက္ကန့်တိုင်းတိုးသော timer component ရေးပြီး unmount ဖြစ်လျှင် interval ကိုရှင်းပါ။
Lifecycle Hooks — Vue.js