Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
(_灬幸福相伴
Docs
提交
d61b6658
D
Docs
项目概览
(_灬幸福相伴
/
Docs
与 Fork 源项目一致
Fork自
OpenHarmony / Docs
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d61b6658
编写于
12月 19, 2022
作者:
O
openharmony_ci
提交者:
Gitee
12月 19, 2022
浏览文件
操作
浏览文件
下载
差异文件
!12635 【轻量级 PR】:update zh-cn/application-dev/application-models/common-event-publish.md.
Merge pull request !12635 from zyjhandsome/N/A
上级
425bd771
2c65458a
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
8 addition
and
8 deletion
+8
-8
zh-cn/application-dev/application-models/common-event-publish.md
...pplication-dev/application-models/common-event-publish.md
+8
-8
未找到文件。
zh-cn/application-dev/application-models/common-event-publish.md
浏览文件 @
d61b6658
...
...
@@ -3,9 +3,9 @@
## 场景介绍
当需要发布某个自定义公共事件时,可以通过
publish(
)方法发布事件。发布的公共事件可以携带数据,供订阅者解析并进行下一步处理。
当需要发布某个自定义公共事件时,可以通过
[
publish()
](
../reference/apis/js-apis-commonEvent.md#commoneventpublish
)
方法发布事件。发布的公共事件可以携带数据,供订阅者解析并进行下一步处理。
>
![icon-notice.gif](public_sys-resources/icon-notice.gif)
**须知:**
> **须知:**
> 已发出的粘性公共事件后来订阅者也可以接收到,其他公共事件都需要先订阅再接收,订阅参考[公共事件订阅章节](common-event-subscription.md)。
...
...
@@ -23,17 +23,17 @@
不携带信息的公共事件,只能发布无序公共事件。
1.
导入
CommonEvent
模块。
1.
导入模块。
```
ts
import
commonEvent
from
'
@ohos.commonEventManager
'
;
import
commonEvent
Manager
from
'
@ohos.commonEventManager
'
;
```
2.
传入需要发布的事件名称和回调函数,发布事件。
```
ts
// 发布公共事件
commonEvent
.
publish
(
"
usual.event.SCREEN_OFF
"
,
(
err
)
=>
{
commonEvent
Manager
.
publish
(
"
usual.event.SCREEN_OFF
"
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
`[CommonEvent] PublishCallBack err=
${
JSON
.
stringify
(
err
)}
`
);
}
else
{
...
...
@@ -47,10 +47,10 @@
携带信息的公共事件,可以发布为无序公共事件、有序公共事件和粘性事件,可以通过参数
[
CommonEventPublishData
](
../reference/apis/js-apis-commonEventManager.md#commoneventpublishdata
)
的isOrdered、isSticky的字段进行设置。
1.
导入
CommonEvent
模块。
1.
导入模块。
```
ts
import
commonEvent
from
'
@ohos.commonEventManager
'
;
import
commonEvent
Manager
from
'
@ohos.commonEventManager
'
;
```
2.
传入需要发布的事件名称和回调函数,发布事件。
...
...
@@ -67,7 +67,7 @@
```
ts
// 发布公共事件
commonEvent
.
publish
(
"
usual.event.SCREEN_OFF
"
,
options
,
(
err
)
=>
{
commonEvent
Manager
.
publish
(
"
usual.event.SCREEN_OFF
"
,
options
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
[CommonEvent] PublishCallBack err=
'
+
JSON
.
stringify
(
err
));
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录