码迷,mamicode.com
首页 > 微信 > 详细

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

时间:2018-08-17 20:04:52      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:menu   分享功能   table   from   false   lsp   ESS   iss   title   

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
                }
            },
        }
    }

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

标签:menu   分享功能   table   from   false   lsp   ESS   iss   title   

原文地址:https://www.cnblogs.com/cqlb/p/9494897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!