uni.postMessage
时间: 2023-08-26 07:17:18 浏览: 135
uni.postMessage是一个用于在H5页面和原生App之间进行通信的方法。它可以在H5页面中使用,通过postMessage方法向原生App发送信息。在H5页面中,可以通过uni.postMessage({ data: { action: 'H5来了' } })来发送信息给原生App。这样原生App就可以通过监听message事件来接收来自H5页面的信息,并进行相应的处理。对于Vue页面,可以在created生命周期中添加window.addEventListener('message', this.handleMessage)来监听message事件,而在beforeDestroy生命周期中移除监听器window.removeEventListener('message', this.handleMessage),以确保在组件销毁时不再监听message事件。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [uniapp 与H5通信实操](https://blog.csdn.net/jkhedge/article/details/128715363)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* [uniapp 使用 webview 触发uni.postMessage](https://blog.csdn.net/qwe_aaaaa/article/details/126286725)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文