import emitter from "@ohos.events.emitter";
let event = {
eventId : 1
}
let event11 = {
eventId: 1,
priority: emitter.EventPriority.LOW
};
let eventData = {
data: {
"content": "c",
"id": 1,
"isEmpty": false,
}
};
@Entry
@Component
struct Index {
@State text: string = "";
@State publish: string = "";
onPageShow() {
// 订阅事件
emitter.on(event, (eventData) => {
console.info("huxiubo", `eventData :${JSON.stringify(eventData)}`);
})
}
// 发送事件
publishEmitter() {
emitter.emit(event, eventData)
}
build() {
Column({ space: 10 }) {
Button("发布公共事件")
.size({ width: 260, height: 50 })
.onClick(() => {
this.publishEmitter();
})
}
.padding(10)
.size({ width: "100%", height: '100%' })
}
}
网友评论