---
description: "eventEmitter eventEmitter 事件处理：组件内部部分代码, 通过进行事件监听触发对应方法"
category: date-locale-event
keywords: ["eventEmitter", "事件处理", "日期", "时间", "多语言", "事件", "主题", "页面标题"]
source: "https://www.e-cology.com.cn/utils/eventEmitter/freepass"
---

# eventEmitter eventEmitter 事件处理

## 适用场景

组件内部部分代码, 通过进行事件监听触发对应方法

## 能力说明

使用说明: 基于 eventemitter3 库

## 检索符号

- `eventEmitter`

## 代表示例

```js
import { eventEmitter } from '@weapp/utils';

const fn1 = () => {
  console.log('fn1 execute');
};

const fn2 = () => {
  console.log('fn2 execute');
};
const fn3 = () => {
  console.log('fn3 execute');
};
const fn4 = () => {
  console.log('fn4 execute');
};
const fn5 = () => {
  console.log('fn5 execute');
};

const listener1 = (num) => {
  console.log(num);
  console.log('添加监听');
  eventEmitter.off('weapp', 'showModel', fn2);
};
eventEmitter.on('weapp', 'showModel', fn1);
eventEmitter.on('weapp', 'showModel', fn2);
eventEmitter.once('weapp', 'showModel', fn3);
eventEmitter.addListener('weapp', 'showModel', listener1, '2222');
eventEmitter.emit('weapp', 'showModel', 'test');
eventEmitter.emit('weapp', 'showModel', 'test');
```

## 深入阅读
- [在线免登文档](https://www.e-cology.com.cn/utils/eventEmitter/freepass)

> 本卡用于快速选型。参数、返回值、限制和完整示例以原始文档为准。
