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 = this
console.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)
}
}
}
}
版权声明:本文为qq_46199553原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。