提交 187ea4c4 编写于 作者: E echoorchid

update docs for messagePort, check nullptr

Signed-off-by: Nechoorchid <huweidong2@huawei.com>
上级 7e5ce65b
......@@ -46,7 +46,11 @@ struct WebComponent {
Column() {
Button('close')
.onClick(() => {
this.msgPort[1].close();
if (this.msgPort && this.msgPort[1]) {
this.msgPort[1].close();
} else {
console.error("msgPort is null, Please initialize first");
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
......@@ -1383,7 +1387,11 @@ struct WebComponent {
Button('SendDataToHTML')
.onClick(() => {
try {
this.ports[1].postMessageEvent("post message from ets to HTML");
if (this.ports && this.ports[1]) {
this.ports[1].postMessageEvent("post message from ets to HTML");
} else {
console.error(`ports is null, Please initialize first`);
}
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
......@@ -1434,7 +1442,11 @@ window.addEventListener('message', function (event) {
// 3. 使用h5Port往ets侧发送消息.
function PostMsgToEts(data) {
h5Port.postMessage(data);
if (h5Port) {
h5Port.postMessage(data);
} else {
console.error("h5Port is null, Please initialize first");
}
}
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册