小程序转发问题

小程序转发有两种方式
1.点击右上角转发
2.页面上有分享按钮

第一种

// 在page的js文件中加入以下代码
/** * 用户点击右上角分享 */ onShareAppMessage: function (t) { var o = this; return { path: "pages/quick-purchase/index/index?user_id=" + wx.getStorageSync("user_info").id, success: function(t) { 1 == ++share_count && a.shareSendCoupon(o); } }; }

中间可以写返回参数 和返回路径

第二种
1.在wxml里写所要点击的按钮


2.在js页面
//gbi指用户所要传递的参数(可以没有参数)
//path:用户需要分享的页面

    onShareAppMessage: function (res) {
      	  let gbid = res.target.dataset.info.order_id;
          return {
              title: '分享',
              path: '/pages/imgroup/imgroup?tgid=' + gbid,
              imageUrl: 'https://......./img/groupshare.png',  //用户分享出去的自定义图片大小为5:4,
              success: function (res) {
        	   // 转发成功
	        	        wx.showToast({
	        	          title: "分享成功",
	        	          icon: 'success',
	        	          duration: 2000
	        	        })
               },
              fail: function (res) {
                // 分享失败
              },
        }
   }

你可能感兴趣的:(小程序)