微信小程序怎么跟H5页面进行交互

lewis 2018-12-08 25次阅读

在微信小程序实现跟H5页面进行交互的方法

1.使用web-view标签内嵌网页,通过 src 携带参数,通过 @message 接收h5传回的数据实现交互

<template>
<view>
<web-view :src="activity.imgUrl?id=xxx" @message="postMessage"></web-view>
</view>
</template>

2.在h5页面通过 wx.miniProgram.postMessage 向小程序传递参数

<scripttype="text/javascript"src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>

<scripttype="text/javascript">

wx.miniProgram.postMessage({

data:'foo'

})

</script>




发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。