H5页面向小程序传递参数

H5页面 js;

<script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
  
 $(function () {
       //小程序发送信息
        wx.miniProgram.getEnv(function (res) {
            if (res.miniprogram) {
                var info = {
                    wboid: '1234555555',//参数一
                    wid: '78945454545',//参数二
                };
                var json = JSON.stringify(info);
                wx.miniProgram.postMessage({ data: json });
            }
     });
   });

小程序接受参数:

index.wxml;

<view class="container">
   <web-view src="{{url}}" bindmessage="Test"></web-view>
</view>

index.js;

//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    url:"",
  },
  
  onLoad: function(options) {
    }),
    
  Test: function(e) { 
    var that = this;
    //接受h5页面传过来的参数
    var data = e.detail.data; 
   var wboid= data[0].wboid;
     that.setData({
     url:"https://....wboid="+wboid
    })
  },
})

猜你喜欢

转载自blog.csdn.net/qq_41851047/article/details/81874238