業務背景:在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://www.uj5u.com/qita/242835.html
標籤:其他
