页面内发起转发
通过给
button
组件设置属性open-type="share"
,可以在用户点击按钮后触发Page.onShareAppMessage
事件,相关组件:button。
<button open-type="share">转发</button>
// 3 button 的开放功能<button open-type="share">分享</button>
onShareAppMessage: function(res) {
var that = this;
//console.log('res=====',res);
if (res.from === 'button') {
//console.log('来自页面内转发按钮');
} else if (res.from === 'menu'){
//console.log('右上角菜单转发按钮');
}
// 返回数据
return {
title: that.data.info.name,
path: '/pages/food/info?id=' + that.data.info.id,
success: function(res) {
// 转发成功,可以把当前页面的链接发送给后端,用于记录当前页面被转发了多少次或其他业务
wx.request({
url: app.buildUrl("/member/share"),
data: {
url: utils.getCurrentPageUrlWithArgs()
},
success: function(res) {
//console.log('成功');
}
});
},
fail: function(res) {
// 转发失败
}
}
},