- 网页与小程序之间通信,网页引入JSSDK 1.3.2
- 在web-view中绑定bindmessage事件
网页向小程序 postMessage 时,会在特定时机(小程序后退、组件销毁、分享)触发并收到消息。e.detail = { data }
web-view src='{{url}}' bindtap='toShare' bindmessage="bindmessage"/web-view- 网页中使用wx.miniProgram.postMessage向小程序传递数据对象
单条数据,赋给data:wx.miniProgram.postMessage({data:xxx})多条数据-放入对象中:wx.miniProgram.postMessage({data:{}})- 在小程序中接收传递的数据
bindmessage(e) {//接收web-view传递的参数 this.setData({//存储状态 title: e.detail...., imageUrl: e.detail... }) }, onShareAppMessage(opt) { this.toShare(); let title = this.data.title; let imageUrl = this.data.imageUrl; return { title: title, imageUrl: imageUrl, path: 'pages/...,//小程序跳转路径 success: function (res) { console.log(res) // 转发成功 }, fail: function (res) { console.log(res) // 转发失败 } } },【哈哈镜】100-70新老客神券来了
购买地址:http://t.cn/EXfAZIl
推荐理由:新老客每周可免费领取一张100-70













