微信跳转小程序

微信跳转小程序

<wx-open-launch-weappid="launch-btn"username="gh_xxxxxxxx"path="pages/home/index?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>

按钮显示不出的原因:

  1. wx.config 配置不对 需要加入 wx-open-launch-weapp
openTagList: ['wx-open-launch-weapp']
  1. 将 < template> 替换为 < script type=“text/wxtag-template”>
  2. 服务号js安全域名未配置