1、h5跳转到小程序
首先引入js文件
<script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
跳转方法
①跳转到小程序内页
wx.miniProgram.navigateTo({
url: '/pages/content/content',
//url: '/pages/content/content?id=1', 传参
});
②跳转到小程序tabbar页面
wx.miniProgram.switchTab({url: "/pages/index/index"})
2、小程序跳转到h5
①用webview标签,传入h5地址
<web-view src="{{path}}"></web-view>
②传参
this.setData({
path: options.path + '?data=' + '哈哈哈'
})
3、h5页面获取小程序传参
function getSearchString(key, Url) {
var str = Url;
str = str.substring(1, str.length);
var arr = str.split("?");
var obj = new Object();
for (var i = 0; i < arr.length; i++) {
var tmp_arr = arr[i].split("=");
obj[decodeURIComponent(tmp_arr[0])] = decodeURIComponent(tmp_arr[1]);
}
return obj[key];
}
var search = window.location.search;
var data = getSearchString('data', search);
4、小程序获取h5传参
onLoad方法中获取
onLoad: function (options) {
console.log(options.id);
},