- 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任务。