H5頁面向小程式傳遞引數
阿新 • • 發佈:2018-10-31
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 }) }, })