Vue3:生命周期
beforeCreate(建议使用setup代替)created(建议使用setup代替)
setup
beforeMount mounted
beforeUpdate updated
beforeUnmount unmounted
onBeforeMount onMounted
onBeforeUpdate onUpdated
onBeforeUnmount onUnmounted
onErrorCaptured
onRenderTracked
onRenderTriggered
<script> import { onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted, ref } from 'vue' export default { setup () { // 其他的生命周期 onBeforeMount (() => { console.log("App ===> 相当于 vue2.x 中 beforeMount") }) onMounted (() => { console.log("App ===> 相当于 vue2.x 中 mounted") }) // 注意,onBeforeUpdate 和 onUpdated 里面不要修改值 onBeforeUpdate (() => { console.log("App ===> 相当于 vue2.x 中 beforeUpdate") }) onUpdated (() => { console.log("App ===> 相当于 vue2.x 中 updated") }) onBeforeUnmount (() => { console.log("App ===> 相当于 vue2.x 中 beforeDestroy") }) onUnmounted (() => { console.log("App ===> 相当于 vue2.x 中 destroyed") }) return { } } } </script>