知识学堂 > 课程 > 小程序分享

小程序分享

发布日期:2020/6/1 来源:聚恒【返回】

  onShareAppMessage: function (options) {
    //先写一个数组,
    var shareimg = [
      "https://bb.parwiheart.com/image/27.jpg","https://bb.parwiheart.com/image/47.png"
    ]
    //在写随机数
    var randomImg = shareimg[Math.floor(Math.random() * shareimg.length)];
    var that = this;
    
    var data = options.target.dataset;
    //最后就直接可以在分享中调用
    return {
      title: "", //此处为标题,
      path: "/pages/RunInvite/RunInvite?id=" + data.id+"&openid="+data.openid, //此处为路径,
      imageUrl: randomImg, //此处就是写的随机分享图片,
      success: function (res) {
        //这里为分享成功后的回调函数,
      },
      fail: function (res) {
        //此处为转发失败后的回调函数
      }
    }
  },
  //调用转发   <button open-type="share" data-id="{{ item.id }}" data-title="{{item.title}}"> ********************** web-view标签是不允许分享到朋友圈的