您的位置:宽带测速网 > 网络知识 > 微信小程序怎么跟H5页面进行交互

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

2025-06-17 10:09来源:互联网 [ ]

在微信小程序实现跟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>