一、js式分享(onShareAppMessage)
在onShareAppMessage方法里自定义分享
// 分享
onShareAppMessage: function () {
return {
title: '张无忌获得2023年度价值观明星卡!',
imageUrl: '../../../../images/share/medal-honest.png',
path: '/pages/main/opinionValue/cardInfo/cardInfo?unionid=' + this.data.unionid + "&card_id=" +
this.data.card_id + '&jobnumber=' + this.data.jobnumber + '&phone=' + this.data.phone
}
}
最终效果如上图所示
其中title为标题、imageUrl为卡片封面图片如果路径找不到则默认分享页面的缩略图、path为要分享出去的页面,可以携带一些参数。
二、按钮式分享
<!-- 按钮转发 -->
<button data-name="shareBtn" open-type="share">转发</button>
只需要加上button标签,属性写上open-type="share"即可,也是可以传参的。
点击按钮后会调用onShareAppMessage方法。
三、开启分享朋友圈
onLoad: function (options) {
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
}
1)shareAppMessage为分享到朋友,shareTimeline为分享到朋友圈
2)开启分享到朋友只要配置shareAppMessage即可,分享到朋友圈则shareAppMessage和shareTimeline都要开启
3)如果不需要分享功能,去掉wx.showShareMenu同时去掉onShareAppMessage