<view class='carDesc carDesc1'>
<text>金氏养猪场</text>
<button class='share' id="shareBtn" open-type="share" type="primary" hover-class="other-button-hover">
<image src='../../images/share.png'></image>
分享
</button>
</view>
上面是 WXML 代码
下面是 js代码
onShareAppMessage: function (ops) {
if (ops.from === 'button') {
// 来自页面内转发按钮
console.log(ops.target)
}
return {
title: 'xx小程序',
path: 'pages/index/index',
success: function (res) {
// 转发成功
console.log("转发成功:" + JSON.stringify(res));
},
fail: function (res) {
// 转发失败
console.log("转发失败:" + JSON.stringify(res));
}
}
}
回调结果:
回调类型 errMsg 说明 success shareAppMessage:ok 转发成功 fail shareAppMessage:fail
cancel 用户取消转发 fail shareAppMessage:fail (detail message) 转发失败,其中 detail message 为详细失败信息
微信小程序 分享实现
最新推荐文章于 2024-08-27 09:57:23 发布
本文介绍了一个小程序中的分享功能实现方式,包括WXML代码示例及JS逻辑处理,展示了如何通过按钮触发分享,并处理分享成功的回调。
4790

被折叠的 条评论
为什么被折叠?



