Uniapp 微信小程序端分享

Uniapp 微信小程序端分享

首先小程序账号微信需要认证,否则不能分享,
其次必须要有这两个函数 onShareAppMessage 和 onShareTimeline 这两个函数跟data平级,
然后是这两个函数的内容如下 参数res需要传,即使不用也要传参,否则自定义的样式无效,只能分享当前页面的截图。

onShareAppMessage(res) {
	if (res.from === 'button') {// 来自页面内分享按钮
		console.log(res.target)
	}
	return {
		title: this.shareTitle,
		path: this.sharePath,
		imageUrl: this.shareImgUrl
	}
}

点击小程序右上角的分享按钮或自动以share按钮
在view 中添加分享按钮

<button open-type="share" @click="shareTest">分享按钮1</button>
<button open-type="share" @click="shareTest2">分享按钮1</button>

可在同一个页面添加不同的分享内容,在methods中添加

shareTest(){
	this.shareTitle = '测试页面A';
	this.sharePath = '/pages/xx/xx';
	this.shareImgUrl = '/static/icons/yy.png';
},
shareTest2(){
	this.shareTitle = '测试页面B';
	this.sharePath = '/pages/xxx/xx?id=123';
	this.shareImgUrl =  '/static/images/xx.png';
}

文章为个人工作记录,如有不妥之处请私信,3Q!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值