H5页面向小程序传递参数

H5页面 js;


  
 $(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 });

                //这种跳转方式是跳转到小程序指定页面 并携带此参数
               // wx.miniProgram.reLaunch({ url: '../../pages/pay/pay?json=' + json });
            }
     });
   });

小程序接受参数:

index.wxml;


   

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
    })
  },
})

 

你可能感兴趣的:(小程序)