Skip to content

defineComponent(组件)

defineComponent() 是原生 Component() 的超集:在组件 lifetimes.attached 阶段初始化运行时并执行同步 setup()setup() 返回对象会合并到组件实例,模板可直接使用。

lifetimes / pageLifetimes 对应的 hooks

说明:wevu 的 onXXX() 必须在 setup() 同步阶段注册;因此,发生在 setup() 之前的生命周期(如 lifetimes.created)没有对应的 wevu hook 可用,只能写原生回调。

lifetimes(组件生命周期)

小程序字段回调名对应 wevu hook说明
lifetimes.createdcreated-发生在 setup() 之前;只能使用原生回调
lifetimes.attachedattachedsetup()wevu 在此阶段 mount 并执行 setup()
lifetimes.readyreadyonReady / onMounted组件就绪(内部做了重复触发去重)
lifetimes.movedmovedonMoved组件移动(例如在节点树中被移动)
lifetimes.detacheddetachedonUnload / onUnmounteddetached 时 teardown,并触发 onUnload
lifetimes.errorerroronError组件错误(参数透传原生回调)

pageLifetimes(页面对组件的影响)

小程序字段回调名对应 wevu hook说明
pageLifetimes.showshowonShow / onActivated所在页面显示
pageLifetimes.hidehideonHide / onDeactivated所在页面隐藏
pageLifetimes.resizeresizeonResize所在页面尺寸变化(参数透传原生回调)

Released under the MIT License.