H5跳转到小程序wx-open-launch-weapp

本文介绍了如何在HTML和Vue页面中引用JS并配置微信小程序,包括设置微信配置参数、使用`wx.openLaunchWeapp`标签及监听打开事件。详细步骤展示了从添加JS库到实现打开小程序功能的过程。
摘要由CSDN通过智能技术生成

1、引用JS

 <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>

}
2、微信配置
wx.config({
debug: true,
appId: ‘’,
timestamp:, // 必填,生成签名的时间戳
nonceStr: ‘’, // 必填,生成签名的随机串
signature: ,// 必填,签名
jsApiList: [‘onMenuShareTimeline’], // 必填,需要使用的JS接口列表
openTagList: [‘wx-open-launch-weapp’] // 可选,需要使用的开放标签列表,例如[‘wx-open-launch-app’]
});
3、html代码
html页面

 <wx-open-launch-weapp id="launch-btn"
       username="gh_***"
       path="">   // path为空,跳转到小程序首页,不为空,则指定小程序页面
                    <template>
                        <style>
                            .btn {
                                padding: 12px;
                            }
                        </style>
                        <button class="btn">打开小程序</button>
                    </template>
                </wx-open-launch-weapp>

vue页面或引用vue.js的页面

   <wx-open-launch-weapp username="gh_***"
                                  path=""
                                  style="display: inline-block;width: 44vw;height: 17vw;">
                <script type="text/wxtag-template">
                    <style>
                        .btn {
                            width: 100%;
                        }
                    </style>
                    <button class="btn">打开小程序</button> 
                </script>
            </wx-open-launch-weapp>
  1. 操作
    var btn = document.getElementById(‘launch-btn’);
    btn.addEventListener(‘launch’, function (e) {
    console.log(‘success’);
    });
    btn.addEventListener(‘error’, function (e) {
    console.log(‘fail’, e.detail);
    });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值