vue2 中有 11 个,8 个常见的,两 个缓存组件的,1 个错误捕获的;vue3 中常见剩 6 个,因为有两个用 setup 代替了。

data数据挂载之前
beforeCreate -> 使用 setup()

data数据挂载
created -> 使用 setup()

模板语法挂载了,但是没有渲染
beforeMount -> onBeforeMount

模板语法渲染结束
mounted -> onMounted

页面dom更新之前
beforeUpdate -> onBeforeUpdate

dom更新之后
updated -> onUpdated

vue实例销毁之前
beforeDestroy -> onBeforeUnmount

vue实例销毁之后
destroyed -> onUnmounted
errorCaptured -> onErrorCaptured

import { onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount} from 'vue'

setup() {

        const data = resctive({

                msg:"你好!"

        })

        // 数据渲染前

        onBeforeMount(() => {

        })

        // 数据渲染后

        onMounted(() => {

        })

        // dom更新前

        onBeforeUpdate(() => {

        })

        // dom更新后

        onUpdated(() => {

        })

        return{

                ...toRefs(data)

        }

}