1、借助uniapp中页面生命周期钩子onShareAppMessage(OBJECT)用户点击右上角分享
在 js 中定义 onShareAppMessage 处理函数(和 onLoad 等生命周期函数同级),设置该页面的分享信息。
onShareAppMessage(res) {
if (res.from === 'button') {
// 来自页面内分享按钮
console.log(res.target);
}
return {
title: 'xxx', //分享的名称
path: '/pages/index/xxx?id=xx',//分享详情页面时,需要把所需参数代入
mpId: 'xxxx', //此处配置微信小程序的AppId
};
},
2、借助uniapp中页面生命周期钩子onShareTimeline监听用户点击右上角转发到朋友圈
在 js 中定义 onShareTimeline 处理函数(和 onLoad 等生命周期函数同级),转发朋友圈无需携带页面所需要的参数
onShareTimeline(res) {
return {
title: 'xxx',
type: 0,
summary: '',
};
},