React 中事件总线使用流程

Posted 闲人

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React 中事件总线使用流程相关的知识,希望对你有一定的参考价值。

依赖库events

eventBus.js

import { EventEmitter } from \'events\';
export default new EventEmitter();

发布组件

import Bus from \'../../EventBus\';
<Button type=\'primary\' onClick={ () => { Bus.emit(\'changeSiblingsData\', count) }}>提交</Button>

订阅组件

import Bus from \'../../EventBus\';
Bus.addListener(\'changeSiblingsData\', (count)=> {
    alert(count); 
});

以上是关于React 中事件总线使用流程的主要内容,如果未能解决你的问题,请参考以下文章