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!