current position:Home>Life cycle comparison between vue2 and vue3

Life cycle comparison between vue2 and vue3

2022-01-26 22:11:02 Top of migrant workers in the new era

Periodic comparison

vue2 vue3
beforeCreate setup
created setup
beforeMount onBeforeMount
mounted onMounted
beforeUpdate onBeforeUpdate
updated onUpdated
activeted onActiveted
deactiveted onDeactiveted
beforeDestory onBeforeUnmount
destoryed onUnmounted

usage

vue2 Life cycle and data / methods The same level is used as a function , such as created() {}

data() {
    
    return {
    }
},
created() {
    
    ...
}

vue3 Life cycle in setup In the outermost layer , No need to load on demand , Other life cycles have to be loaded on demand to use

import {
     omMounted } from 'vue'

setup() {
    
    onMounted(() => {
     ... })
}

copyright notice
author[Top of migrant workers in the new era],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262211004979.html

Random recommended