onShareAppMessage(Object object)
监听用户点击页面内转发按钮(button 组件 open-type=“share”)或右上角菜单“转发”按钮的行为,并自定义转发内容。
注意:只有定义了此事件处理函数,右上角菜单才会显示“转发”按钮
Page({ onShareAppMessage() { const promise = new Promise(resolve => { setTimeout(() => { resolve({ title: '自定义转发标题' }) }, 2000) }) return { title: '自定义转发标题', path: '/page/user?id=123', promise } }})
onShareAppMessage(res){var that = thisconsole.log(that.goods_data)if(res.from==='button'){//分享按钮return {title:that.goods_data.share_title||that.goods_data.goods_name,// path: '',imageUrl:that.goods_data.share_img||that.goods_data.main_img,success: function (res) { if(res.errMsg == 'shareAppMessage:ok'){console.log("成功",res) }},fail:function(res){ console.log("失败",res) }}}else{return {title:that.goods_data.share_title||that.goods_data.goods_name,// path: '',imageUrl:that.goods_data.share_img||that.goods_data.main_img,success: function (res) { if(res.errMsg == 'shareAppMessage:ok'){console.log("成功",res) }},fail:function(res){ console.log("失败",res) }}}}
来源地址:https://blog.csdn.net/qq_46199553/article/details/128851375