Vue3 lifecycle hooks

common life hook

name execution time
setup Component initialization
onBeforeMount before the component is mounted
onMounted After the component is mounted
onBeforeUpdate Responsive state changes before updating the DOM tree
onUpdated After updating the DOM tree in response to state changes
onBeforeUnmount Before component uninstallation
onUnmounted After the component is unmounted

<KeepAlive> life hook

When using <KeepAlive> to cache components, the cached components will not be destroyed and created frequently, causing some of the above components to not be executed, and then there will be two more above hooks.

name execution time
onActivated When a component (page) is inserted (displayed) into the DOM
onDeactivated When the component (page) is removed (not displayed) from the DOM

Guess you like

Origin blog.csdn.net/weixin_48165407/article/details/124561777