生命周期
<script setup lang="ts">
import { ref, onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted } from 'vue'
const changeStr = () => {
str.value = '小强'
}
const hellowDiv = ref<HTMLDivElement>()
const str = ref<string>('小满')
onBeforeMount(() => {
console.log('渲染之前', hellowDiv.value)
})
onMounted(() => {
console.log('渲染之后', hellowDiv.value)
})
onBeforeUpdate(() => {
console.log('更新之前', hellowDiv.value?.innerText)
})
onUpdated(() => {
console.log('更新之后', hellowDiv.value?.innerText)
})
onBeforeUnmount(() => {
console.log('卸载之前')
})
onUnmounted(() => {
console.log('卸载之后')
})
</script>
<template>
<div ref="hellowDiv">
{{ str }}
</div>
<button @click="changeStr">修改str</button>
</template>
<style scoped>
</style>