VUE3.0生命周期函数

什么是生命周期:

    1.vue中每个组件都是独立的,每个组件都有一个属于它的生命周期,
    2.从一个组件创建、数据初始化、挂载、更新、销毁,这就是一个组件所谓的生命周期,强调的是一个时间段。

在vue3中,新增了一个setup生命周期函数,setup执行的时机是在beforeCreate生命函数之前执行,因此在这个函数中是不能通过this来获取实例的;同时为了命名的统一,将beforeDestroy改名为beforeUnmount,destroyed改名为unmounted.

Options API 生命周期 和 Composition API 生命周期

1、 Options API 生命周期
    1. beforeCreate   
    2. created        
    3. beforeMount    
    4. mounted        
    5. beforeUpdate   
    6. updated        
    7. beforeUnmount  
    8. unmounted         

2、 Composition API 生命周期
    1. beforeCreate   ===> setup()
    2. created        ===> setup()
    3. beforeMount    ===> onBeforeMount
    4. mounted        ===> onMounted
    5. beforeUpdate   ===> onBeforeUpdate
    6. updated        ===> onUpdated
    7. beforeUnmount  ===> onBeforeUnmount
    8. unmounted      ===> onUnmounted

猜你喜欢

转载自blog.csdn.net/shi15926lei/article/details/128259976