本章介绍到的是Vue3.x的生命周期
从Vue2.x到Vue3.x
beforeCreate > 移除(setup)
created > 移除(setup)
beforeMount > onBeforeMount
mounted > onMounted
beforeUpdate > onBeforeUpdate
updated > onUpdated
beforeUnmount > onBeforeUnmount
unmounted > onUnmounted
errorCaptured > onErrorCaptured
renderTracked > onRenderTracked
renderTriggered > onRenderTriggered
例:
import { onMounted } from 'vue';
export default {
setup() {
onMounted(() => {
console.log('Component is mounted!')
})
}
}
下一章:(十)provide和inject
上一章:(八)观察者 - watch
ps:你多学一种本事,就少说一句求人的话。