uniapp微信小程序转发分享朋友圈实现方法

uniapp微信小程序转发分享朋友圈实现方法

一、编写share函数

export default{

    // 监听用户点击右上角菜单的「转发」按钮时触发的事件
    onShareAppMessage(res) {
		console.log(res)
		if (res.from === 'button') {
			// 来自详情页页面内分享按
			return {
				title: "分享标题信息:"+res.target.dataset.title,
				path: '',
				imageUrl: '',
				success: function(res) {
					// 转发成功
					console.log('转发成功')
				},
				fail: function(res) {
					// 转发失败
				}
			};
		} 
        // 设置转发的参数
        return {
            title: "分享标题",
            // path: '',
            imageUrl: "",
            success: function(res) {
                console.log(res, '发生过是');
                if (res.errMsg == 'shareAppMessage:ok') {
                    console.log("成功", res)
                }
            },
            fail: function(res) {
    
                console.log("失败", res)
    
            }
        }
    },
    // 分享到朋友圈
     onShareTimeline:function(res){
		
        return {
          title: '分享标题',
          imageUrl:'/static/logo.png',
          query:''      
        }
      },
      // 收藏
      onAddToFavorites:function(res) {
        return {
          title: '分享标题',
          imageUrl:'/static/logo.png',
          query: '',
        }
      }
}

二、import share from “@/utils/share.js”

为了使用方便,不用再每个页面重复引入share,直接在main.js中引入

三、【自定义分享标题】详情页按钮分享:通过h5 data-title属性传递详情页标题

页面内发起转发:通过给 button 组件设置属性 open-type=“share”,可以在用户点击按钮后触发 Page.onShareAppMessage 事件,相关组件:button

<button v-if="shareshow" type="primary" class="button share" open-type="share" :data-title="FormAddBid.Name" >点击分享</button>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT 老王

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值