业务背景:在h5中直接跳转到小程序(注意不是返回,是直接打开)

直接上码:
一、config注入:

wx.config({ 
 debug: true,
 appId: '<?php echo $signPackage["appId"];?>',
 timestamp: '<?php echo $signPackage["timestamp"];?>',
 nonceStr: '<?php echo $signPackage["nonceStr"];?>',
 signature: '<?php echo $signPackage["signature"];?>',
 jsApiList: [ 'onMenuShareTimeline','onMenuShareAppMessage'],
 openTagList: ['wx-open-launch-weapp']
});

二、前端代码:

<wx-open-launch-weapp
id="launch-btn"
username="小程序原始id"
path="小程序页面地址"
style="width:100px;height:100px;"
>
<template>
<style>.btn {  padding: 12px;width:100px;height:80px;background:skyblue; }</style>
<button class="btn">打开小程序<button>
</template>
</wx-open-launch-weapp>
<script>
var btn = document.getElementById('launch-btn');
btn.addEventListener('launch', function (e) { 
console.log('success');
});
btn.addEventListener('error', function (e) { 
console.log('fail', e.detail);
});
</script>

※目前仅支持通过微信浏览器访问h5打开小程序

本文地址:https://blog.csdn.net/lzz123987csdn/article/details/111995733