组件件的通信有几种方式

46 阅读1分钟

不加修饰符
@Prop单向 @Link双向 @Observed/@ObjectLink嵌套类对象属性变化 @Provide/@Consume后代组件双向同步、

@StorageProp/@StorageLink全局状态存储也可以实现组件通信

路由传参params @BuilderParam 传递声明式渲染数据

Emitter进行线程间通信 => on劫持数据传递,emit发送

import { emitter } from '@kit.BasicServicesKit';

emitter.on({ eventId: 通信唯一标识 }, (eventData: emitter.EventData): void => { console.log('收到推送的消息:', JSON.stringify(eventData)) });

emitter.emit({ eventId: 通信唯一标识, priority: emitter.EventPriority.LOW }, { data: { content: 'c', id: 1, isEmpty: false } });