时间:2022-12-06 01:23
在h5页面中连接小程序的方法
1.首先,在小程序页面内嵌h5网页;
<view class="page-body">
<web-view src="https://xxx.com/test.html"></web-view>
</view>
2.在h5网页中引入json文件,并调用wx.miniProgram.navigateTo方法连接小程序;
<!DOCTYPEhtml><html>
<head>
<metacharset="UTF-8">
<title>h5跳转小程序</title>
</head>
<body>
<h3align="center">正在跳转到小程序...</h3>
<scripttype="text/javascript"src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
<script>
wx.miniProgram.navigateTo({url:'/index/index?phone=18012121212'})
</script>
</body>
</html>
3.最后,在小程序页面接受h5页面的参数,即可;
<viewclass="page-body">{{phone}}
</view>
index.json
Page({
data:{
phone:''
},
onLoad:function(options){
varthat=this;
/*获取参数*/
varphone=options.phone
that.setData({
phone:phone,
})
}
})