微信小程序 通过button实现转发分享功能。判断是不是好友点进来的还是自己点进来的

效果图展示:

代码展示:

share.wxml

        

<button open-type="share">转发</button>

 share.js

Page({
  /**
   * 页面的初始数据
   */
  data: {
 
  },
 
  /**
   * 用户点击右上角 和 button  实现分享
   */
  onShareAppMessage: function (res) {
    if(res.from === 'button'){
      console.log('触发页面内的分享按钮',res.target);
    }else if(res.from === 'menu'){
      console.log('触发右上角的分享按钮')
    }
    return{
      title:'你好,我是标题',    // 转发标题
      path: '',     // 当前页面 path ,必须是以 / 开头的完整路径
      imageUrl:'../../images/lemon.png'   
    }
  }
})

判断是不是好友点进来的还是自己点进来的:

onShareAppMessage: function(res) {
    if (res.from === 'button') {
      console.log("来自页面内转发按钮");
      console.log(res.target);
      return {
        title: this.data.shareTitle,
        imageUrl: this.data.shareImage, // 图片 URL
        path: '/pages/my_dial/my_dial_new?rootOpenId=' + wx.getStorageSync('openId') + '&activityId=' + activityId
      }
    } else {
      console.log("来自右上角转发菜单")
      console.log(res);
      return {
        title: this.data.shareTitle,
        imageUrl: this.data.shareImage, // 图片 URL
        path: '/pages/my_dial/my_dial_new?activityId=' + activityId
      }
    }
},

猜你喜欢

转载自blog.csdn.net/aaa123aaasqw/article/details/130683630