Home > Article > WeChat Applet > WeChat Mini Program Example: Judgment Code for Sharing to One Person or to a Group
The content of this article is about WeChat applet examples: the code for judging whether to share with one person or with a group. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.
The sharing function of the WeChat applet can no longer get the sharing callback on the latest version of the IDE. The official API has also deleted the corresponding callback function. It seems to have been cut off, but the real machine test still works Okay, without further ado, here’s the code:
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; } }, } }
Related recommendations:
How to limit the size of WeChat applet when uploading pictures (with code)
Mini Program: How to dynamically add and delete JSON object arrays (with code)
The above is the detailed content of WeChat Mini Program Example: Judgment Code for Sharing to One Person or to a Group. For more information, please follow other related articles on the PHP Chinese website!