//Parent.vue
<template>
<h1>生命周期 </h1>
<Com/>
</template>
<script setup lang='ts'>
import Com from '../components/Com.vue'
</script>
<style>
</style>
//Com.vue
<template>
<p>我是子组件</p>
</template>
<script setup lang='ts'>
import {onBeforeMount,onMounted,onBeforeUpdate,onUpdated,onBeforeUnmount,onUnmounted} from 'vue'
/**
* 在setup语法模式中,没有beforeCreate created这两个生命周期,setup去代替
*/
console.log('setup')
//挂载前
onBeforeMount(()=>{
//onBeforeMount无法读取到dom元素
})
//挂载完成
onMounted(()=>{
})
//更新前
onBeforeUpdate(()=>{
//获取更新前的dom
})
//更新完成
onUpdated(()=>{
//获取更新之后的dom
})
//卸载前
onBeforeUnmount(()=>{
})
//卸载完成
onUnmounted(()=>{
})
</script>
<style>
</style>