当前位置:Web前端 > > 正文

h5打开小程序点允许(html5跳转小程序wx-open-launch-weapp踩坑)

时间:2021-10-22 07:31:06类别:Web前端

h5打开小程序点允许

html5跳转小程序wx-open-launch-weapp踩坑

因为IOS最新版微信取消了浮窗功能,小程序后台狠毒用户反馈进入不方便了,目前公众号还支持浮窗,于是需求出来了,浮窗一个H5,在H5中一键打开小程序,阅读文档得知,微信对公众号网页开发有开放标签,可以打开App或小程序,但是过程中遇到不少坑以下为记录爬坑。

1.正常操作,公众号后台绑定域名
2.引入weixin.js 目前是1.6.0版本
3.调用wx.config 在openTagList中加入要使用的开放标签
接下来坑来了,文档上使用示例如下

  • <wx-open-launch-weapp
      id="launch-btn"
      username="gh_xxxxxxxx"
      path="pages/home/index.html?user=123&action=abc"
    >
      <template>
    <style>.btn { padding: 12px }</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> 
    
    
  • 贴在vue中 无法使用,排查发现是template标签的问题

  • <li class="center" style="width: 100%" ref="launchBtnHome">
          <wx-open-launch-weapp id="launch-btn" username="gh_xxxxxxxx" path="pages/index/index/index" ref="launchBtn">
            <script type="text/wxtag-template">
              <style>
                .jump-btn {
                  height: 44px;
                  line-height: 44px;
                  border: none;
                  font-size: 16px;
                  color: #ffffff;
                  background-color: #f94048;
                  text-align: center;
                }
              </style>
              <li class="jump-btn">打开小程序</li>
            </script>
          </wx-open-launch-weapp>
        </li>
    
    
  • 这样基本功能就实现了,但是样式没法居中,在里面写的style很多不生效,最后解决方案是: 给开放标签外部套一个li 给li写样式,开放标签本身也可以通过ID选择器直接写样式, 至此开发完成,后续老板想在created中直接模拟点击按钮唤起小程序,试了ref获取dom后调用click方法可是不生效,发现论坛上也没有相关解决方案,微信开放社区中也有相关问题挂起并未解决,大家要是有什么好的方法可以下面讨论下一起解决下

    另附微信开放社区问题挂起的地址https://developers.weixin.qq.com/community/develop/doc/0004604a1d8df03099ba91c965b400

    到此这篇关于html5跳转小程序wx-open-launch-weapp踩坑 的文章就介绍到这了,更多相关html5跳转小程序内容请搜索开心学习网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持开心学习网!

    上一篇下一篇

    猜您喜欢

    热门推荐