文章目录
文章参考触发用户转发onShareAppMessage(Object object)自定义转发内容案例点击分享链接进入小程序
开发工具模拟小程序分享到群卡片进入小程序
文章参考
wx小程序 转发
触发用户转发
<button open-type="share">转发
</button>
用户点击按钮后触发 Page.onShareAppMessage 事件
onShareAppMessage(Object object)
监听用户点击页面内转发按钮(button 组件 open-type=“share”)或右上角菜单“转发”按钮的行为,并自定义转发内容。
注意:只有定义了此事件处理函数,右上角菜单才会显示“转发”按钮
自定义转发内容
案例
onShareAppMessage
: function(res
) {
if (res
.from === 'button') {
console
.log(res
.target
)
}
return {
title
: '测试分享标题',
imageUrl
: "http://n.sinaimg.cn/news/1_img/dfic/72f96829/107/w1024h683/20191031/4df3-ihqyuym6659554.jpg",
path
: '/pages/myVisitorCode/myVisitorCode?id=654321&name=huanghaili'
}
},
效果如图
点击分享链接进入小程序
被分享的打开的链接页面,通过onLoad 生命周期函数获取传递的参数
onLoad
: function (query
) {
console
.log(query
);
this.messageCardParams
= JSON.stringify(query
);
},
开发工具模拟小程序分享到群卡片进入小程序