未验证 提交 e92a736c 编写于 作者: Z zyjhandsome 提交者: Gitee

update zh-cn/application-dev/application-models/common-event-unsubscription.md.

CommonEvent修改为commonEventManager

start build
Signed-off-by: zyjhandsome's avatarzyjhandsome <zyjhandsome@126.com>
Signed-off-by: Nzyjhandsome <zhaoyingjun2@huawei.com>
上级 8e1e5e41
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
## 场景介绍 ## 场景介绍
订阅者完成业务需要时,需要主动取消订阅,订阅者通过下面方法取消订阅事件。 订阅者完成业务需要时,需要主动取消订阅,订阅者通过调用[unsubscribe()](../reference/apis/js-apis-commonEvent.md#commoneventunsubscribe)方法取消订阅事件。
## 接口说明 ## 接口说明
...@@ -15,25 +15,25 @@ ...@@ -15,25 +15,25 @@
## 开发步骤 ## 开发步骤
1. 导入CommonEvent模块。 1. 导入模块。
```ts ```ts
import commonEvent from '@ohos.commonEventManager'; import commonEventManager from '@ohos.commonEventManager';
``` ```
2. 根据[事件订阅章节](common-event-subscription.md)的步骤来订阅某个事件。 2. 根据[公共事件订阅](common-event-subscription.md)章节的步骤来订阅某个事件。
3. 调用CommonEvent中的unsubscribe方法取消订阅某事件。 3. 调用CommonEvent中的unsubscribe()方法取消订阅某事件。
```ts ```ts
// subscriber为订阅事件时创建的订阅者对象 // subscriber为订阅事件时创建的订阅者对象
if (subscriber !== null) { if (subscriber !== null) {
commonEvent.unsubscribe(subscriber, (err) => { commonEventManager.unsubscribe(subscriber, (err) => {
if (err) { if (err) {
console.error(`[CommonEvent] UnsubscribeCallBack err=${JSON.stringify(err)}`) console.error(`[CommonEvent] UnsubscribeCallBack err=${JSON.stringify(err)}`);
} else { } else {
console.info(`[CommonEvent] Unsubscribe`) console.info(`[CommonEvent] Unsubscribe`);
subscriber = null subscriber = null;
} }
}) })
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册