小程序跳转h5传参,监听h5返回控件触发跳回小程序参数获取
第一步:小程序获取h5传过来得参数
onLoad(options) {
let that = this
if(options.parmes){
that.setData({
h5Datas: JSON.parse(decodeURIComponent(options.parmes))
})
}
},
//点击跳转到web-view页面
bindViewTap() {
let that = this
wx.navigateTo({
url: '../webView/index?myDatas='+JSON.stringify(that.data.h5Datas)
})
},
第二步骤:新建一个需要跳转h5的webView页面
html
<view class="container log-list">
<web-view bindmessage="handleGetMessage" src="{{url}}"></web-view>
</view>
js
// logs.js
const util = require('../../utils/util.js')
Page({
data: {
url:''
},
//通过分享获取h5返回控件触发传的参数
onShareAppMessage(options) {
let that = this
return {
title: 'title',
path: that.data.url,
success: function (res) {
// that.web_url = return_url
// 转发成功
wx.showToast({
title: "转发成功",
icon: 'success',
duration: 2000
})
},
fail: function (res) {
// 转发失败
}
}
},
//h5返回参数获取
handleGetMessage: function (e) {
// alert(e.detail.data)
console.log(675675675,e.detail.data);
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(666666,options.myDatas)
let that = this
that.setData({
url: 'https://test-three-car-show.sixeco.com/3d/rotate-launcher-h5/?parmesData='+encodeURIComponent(options.myDatas) //拼接的跳转链接
})
},
})