PHP前端开发

微信小程序实例:分享给一个人还是分享到群的判断代码

百变鹏仔 6天前 #前端问答
文章标签 实例

本篇文章给大家带来的内容是关于微信小程序实例:分享给一个人还是分享到群的判断代码,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

微信小程序的分享功能,在最新版库的ide上已经不能拿到分享回调了,官方api也删除了对应的回调函数,看样子是砍掉了,不过真机测试还是可以的,话不多说,上代码:

onLoad: function(options) {    wx.showShareMenu({            //只有拥有 shareTicket 才能拿到群信息,用户每次转发都会生成对应唯一的shareTicket 。            withShareTicket: true        });},onShareAppMessage: function(res) {        var _this = this;        console.log(res);        if (res.from === 'button') {            // 来自页面内转发按钮            _this.data.shareBtn = true;        } else {            //来自右上角转发            _this.data.shareBtn = false;        }        return {            title: '自定义转发标题',            path: 'pages/index/index',            complete: function(res) {                console.log(res);                if (res.errMsg == 'shareAppMessage:ok') {                    //分享为按钮转发                    if (_this.data.shareBtn) {                        //判断是否分享到群                        if (res.hasOwnProperty('shareTickets')) {                            console.log(res.shareTickets[0]);                            //分享到群                            _this.data.isshare = 1;                        } else {                            // 分享到个人                            _this.data.isshare = 0;                        }                    }                } else {                    wx.showToast({                        title: '分享失败',                    })                    _this.data.isshare = 0;                }            },        }    }