方法触发wx-open-launch-weapp 跳转
时间: 2023-10-09 11:13:14 浏览: 94
解决h5跳转小程序样式问题.zip
5星 · 资源好评率100%
要触发`wx-open-launch-weapp`跳转,你可以使用以下方法之一:
1. 在代码中直接调用`wx.openBusinessView()`方法。具体代码如下:
```javascript
wx.openBusinessView({
businessType: 'wx-open-launch-weapp',
extraData: {
username: "gh_*****",
path: "pages/home/home"
},
success: function(res) {
// 成功跳转
},
fail: function(res) {
// 跳转失败
}
});
```
在`extraData`中设置小程序的用户名和路径,然后调用`wx.openBusinessView()`方法来触发跳转。
2. 在`<wx-open-launch-weapp>`标签中添加点击事件,并在事件处理函数中调用`wx.navigateToMiniProgram()`方法。具体代码如下:
```html
<template>
<div class="btn-card">
<h5 class="btn" @click="openMiniProgram">打开小程序</h5>
</div>
</template>
<script>
export default {
methods: {
openMiniProgram() {
wx.navigateToMiniProgram({
appId: '',
path: 'pages/home/home',
success(res) {
// 成功跳转
},
fail(res) {
// 跳转失败
}
})
}
}
}
</script>
```
在点击事件处理函数`openMiniProgram()`中调用`wx.navigateToMiniProgram()`方法来触发跳转。需要注意在`appId`中填入你的小程序的AppID。
无论使用哪种方法,都可以触发`wx-open-launch-weapp`的跳转效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [h5跳转小程序、短信跳转小程序<wx-open-launch-weapp>干货满满](https://blog.csdn.net/Angelheca/article/details/125444337)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [h5跳转微信小程序 wx-open-launch-weapp](https://blog.csdn.net/qzmlyshao/article/details/131070241)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文