刚好项目有个需求H5跳转到微信小程序,今天尝试一下:
1、引入https://res.wx.qq.com/open/js/jweixin-1.6.0.js*(注意要用jweixin-1.6.0.js,低版本不支持,这里掉坑了)*
2、vue项目需要在main.js加上
Vue.config.ignoredElements = ['wx-open-launch-weapp']
3、注册config
let wxConfig = {} //获取从后台传回来的
WX.config({
debug: false,
appId: wxConfig.appId,
timestamp: wxConfig.timestamp,
nonceStr: wxConfig.nonceStr,
signature: wxConfig.signature,
jsApiList: ['wx-open-launch-weapp'], // 必填,需要使用的JS接口列表
openTagList: ['wx-open-launch-weapp'] // 可选,需要使用的开放标签列表,例如['wx-open-launch-app']
})
4、页面加跳转
<wx-open-launch-weapp
id="launch-btn"
username="gh_c6c35a7c7e4a"
path="/pages/detail/activityDetail/index.html?id=2124&type=0"
@error="handleErrorFn"
@launch="handleLaunchFn"
>
<!--
注意:
path结尾注意不要漏了.html
username:需要用到原始id 而不是appid
vue中需要使用script标签代替template插槽 html中使用template
-->
<script type="text/wxtag-template">
<p class="store-tool_tip">点击进入小程序</p>
</script>
</wx-open-launch-weapp>