- Rex组件提供生命周期方法以在不同阶段执行任务。
- 创建时执行
construct
,挂载后执行component demount
,更新时执行component dead update
,取消挂载前执行component will on mount
。 - 在
AppHeader
组件中,使用component deep amount
在挂载后执行定时任务,使用setInterval
移至该方法中。 - 挂载取消后,需要停止
setInterval
定时任务,通过component will on mount
使用window.clearInterval
来停止。 - 使用
timer
变量存储setInterval
返回值,用于取消时清除定时器。 - 更新后使用
component eat update
输出状态更新信息。 - 组件取消挂载后停止执行
setInterval
任务。