Skip to content

生命周期 ​

组件 ​

阶段时机详细选项钩子组合钩子
setup最先被调用无setup()
beforeCreate初始化完成后创建实例,解析 propsbeforeCreate()无
created处理完所有状态信息后处理状态:data、computed、methods、watchcreated()无
beforeMount挂载之前还未创建 DOM 节点beforeMount()onBeforeMount()
mounted挂载之后DOM 已被创建并插入mounted()onMounted()
beforeUpdate更新之前数据更新,而 DOM 尚未更新beforeUpdate()onBeforeUpdate()
updated更新之后DOM 更新完成updated()onUpdated()
beforeUnmount卸载之前实例正常运行,保有所有功能beforeUnmount()onBeforeUnmount()
unmounted卸载之后停止工作,可清理一些副作用,计时器、DOM 事件监听器 或 与服务器的连接等unmounted()onUnmounted()

特殊 ​

阶段时机详细选项钩子组合钩子
activated激活<KeepAlive> 中被激活activated()onActivated()
deactivated未激活<KeepAlive> 中未被激活deactivated()onDeactivated()
errorCaptured捕获错误捕获了后代组件传递的错误时errorCaptured()onErrorCaptured()