在组件内写button分享按钮:(加data-xxx来传参)
<button class="share" openType="share" data-title="标题" :data-img="imgpw"></button>
然后在父类写onShareAppMessage事件:
// 自定义分享标题
onShareAppMessage(res) {
if (res.from === 'button') {
console.log(res.target.dataset)//可以查看组件传的参数
return {
title: "自定义标题",
desc: "自定义描述",
imageUrl: res.target.dataset.img,
path: 'page/index/index' //分享页面
}
}
},