1 uniapph5? ? 和h5頁面 通信
h5?
window.parent.postMessage(message, '*');
uniapph5? ?onload中?
window.addEventListener('message', function (e) {
?? ??? ?// 監聽 message 事件
?? ??? ?//console.log(e.origin)
?? ??? ?console.log('收到的cocos游戲ID',e.data)
?? ??? ?//收到cocos退出游戲返回的指令
?? ??? ?if(e.data){
?? ??? ??? ?uni.navigateTo({
?? ??? ??? ??? ?url:`/pages/salason/salason?id=${e.data}`
?? ??? ??? ?})
?? ??? ?}
?? ?})
2 uniapp app 中 和h5通信
h5? index.html中 引入<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js">
uni.webView.postMessage({ data: { } }) 發送
uniapp app 中
?? ??? ?<web-view :src="tlink" @message="getmessage"></web-view>
//app端接收數據
const getmessage = (e) => {
?? ?console.log('uniapp接收的數據', e.detail.data[0].name)
?? ?if(e.detail.data[0].name){
?? ??? ?uni.navigateTo({
?? ??? ??? ?url:`/pages/salason/salason?id=${e.detail.data[0].name}`
?? ??? ?})
?? ?}
?? ?
}