智能客服
你问我答,随时在线为你解决问题

























在UIAbility中使用EventHub订阅事件,EventHub模块提供了事件中心,提供订阅、取消订阅、触发事件的能力。
参考代码如下:
import { UIAbility } from '@kit.AbilityKit';
export default class EntryAbility extends UIAbility {
onForeground() {
this.context.eventHub.on('myEvent', this.eventFunc);
// 结果:
// eventFunc is called,undefined,undefined
this.context.eventHub.emit('myEvent');
// 结果:
// eventFunc is called,1,undefined
this.context.eventHub.emit('myEvent', 1);
// 结果:
// eventFunc is called,1,2
this.context.eventHub.emit('myEvent', 1, 2);
}
eventFunc(argOne: number, argTwo: number) {
console.log('eventFunc is called, ${argOne}, ${argTwo}');
}
} 参考链接
智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功