<template>
<view>
<button @click="nav">跳转小程序</button>
</view>
</template>
<script>
export default {
data() {
return {
sweixin: 'weixin'
}
},
onLoad() {
var that = this
// #ifdef APP-PLUS
plus.share.getServices(function(s) {
for (var i = 0; i < s.length; i++) {
var t = s[i];
if (t.id == 'weixin') {
that.sweixin = t;
}
}
}, function(e) {
console.log("获取分享服务列表失败:" + e.message);
});
//#endif
},
methods: {
nav() {
var n = this;
console.log('n ===== ', n.sweixi)
//#ifdef APP-PLUS
console.log('sweixin ===== ', n.sweixin);
n.sweixin ? n.sweixin.launchMiniProgram({
id: 'gh_bdad127a996f', // 要修改
path = "/pages/index/index?sharetype=share&id=" + id
}) : plus.nativeUI.alert('当前环境不支持微信操作!');
//#endif
}
}
}
</script>
app 跳转小程序
最新推荐文章于 2024-07-30 14:06:45 发布
这段代码展示了如何在APP-PLUS环境中获取微信分享服务,并实现点击按钮跳转到指定的小程序页面。首先通过plus.share.getServices获取分享服务列表,然后在按钮点击事件中判断当前环境是否支持微信操作,如果支持则调用launchMiniProgram打开微信小程序。
摘要由CSDN通过智能技术生成