wx小程序 button 属性open-typ 用法 按钮分享

wx.ml

  <button class="btn" open-type="share" data-mode="teacher" data-type="1">hello world</button>

wx.js 内wx 定义的分享方法

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    console.log(e)
    let that = this;
    let type = that.data.shareToObjType;
    let mode = e.target.dataset.mode;
    let userInfo = that.data.userInfo;
    let teamId = that.data.teamId;
    let teamName = that.data.teamName;
    if (mode == "teacher") {
      return {
        title: userInfo.name + "邀请您加入机构",
        path: "/pages/common/invitejoinclass/index?type=2&schoolName=" + userInfo.schoolName + "&schoolId=" + userInfo.schoolId,
        imageUrl: "/image/share.png"
      }
    } else {
      if (type == 1) {
        //student
        return {
          title: userInfo.name + "邀请您加入班级",
          path: "/pages/common/invitejoinclass/index?type=1&teamId=" + teamId + "&teamName=" + teamName + "&schoolId=" + userInfo.schoolId + "&schoolName=" + userInfo.schoolName,
          imageUrl: "/image/share.png"
        }
      }
    }
  }
View Code
原文地址:https://www.cnblogs.com/lvlisn/p/15109545.html