微信小程序實例:分享給一個人還是分享到群的判斷代碼


微信小程序的分享功能,在最新版庫的ide上已經不能拿到分享回調了,官方api也刪除了對應的回調函數,看樣子是砍掉了,不過真機測試還是可以的,話不多說,上代碼:

 

  /*
  // 分享功能回調
  onLoad: function (options) {
    wx.showShareMenu({
      //只有擁有 shareTicket 才能拿到群信息,用戶每次轉發都會生成對應唯一的shareTicket 。
      withShareTicket: true
    });
  },

  onShareAppMessage: function () {
    var that = this;
    console.log("onShareAppMessage")
    return {
      title: '穿越換裝',
      path: '/pages/avatarUpload/index/index',
      success: function (res) {
        if (res.errMsg == 'shareAppMessage:ok') {
          if (res.hasOwnProperty('shareTickets')) {
            console.log(res.shareTickets[0]);
            //分享到群
            that.data.qunshare = 1;
            that.data.geshare = 1;
          } else {
            // 分享到個人
            that.data.geshare = 1;
          }
          wx.showToast({
            title: '分享成功',
            icon: 'success',
            duration: 500
          });
          console.log("shareAppMessage:ok"+ "qun"+ that.data.qunshare +"geren"+ that.data.geshare)
        }
      },
      fail: function (res) {
        if (res.errMsg == 'shareAppMessage:fail cancel') {
          wx.showToast({
            title: '分享失敗',
            icon: 'loading',
            duration: 500
          })
        }
        console.log("shareAppMessage:err")
      }
    }
  },
  */

 

真機調試 return中內容無法進去;

 

 

 

--


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM