微信跳转小程序
<wx-open-launch-weapp
id="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>
按钮显示不出的原因:
- wx.config 配置不对 需要加入 wx-open-launch-weapp
openTagList: ['wx-open-launch-weapp']
- 将 < template> 替换为 < script type=“text/wxtag-template”>
- 服务号js安全域名未配置