关于前端:h5跳转小程序-踩坑-wxopenlaunchweapp

9次阅读

共计 1376 个字符,预计需要花费 4 分钟才能阅读完成。

因为 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 标签的问题

<div 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>
          <div class="jump-btn"> 关上小程序 </div>
        </script>
      </wx-open-launch-weapp>
    </div>

这样基本功能就实现了,然而款式没法居中,在外面写的 style 很多不失效,最初解决方案是:给凋谢标签内部套一个 div 给 div 写款式,凋谢标签自身也能够通过 ID 选择器间接写款式,至此开发实现,后续老板想在 created 中间接模仿点击按钮唤起小程序,试了 ref 获取 dom 后调用 click 办法可是不失效,发现论坛上也没有相干解决方案,微信凋谢社区中也有相干问题挂起并未解决,大家要是有什么好的办法能够上面探讨下一起解决下

 另附微信凋谢社区问题挂起的地址 https://developers.weixin.qq.com/community/develop/doc/0004604a1d8df03099ba91c965b400
正文完
 0