微信小程序分享

前言:微信小程序分享有两种方式,一个是js方式另一个是按钮式

一、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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值