小程序分享功能

onShareAppMessage: function (options) {
    //监测页面按钮分享
    if (options.from === 'button') {
      console.log(options.target)
    }
   var that = this;        
    return {
        //标题
     title: "title",
        // 路径(path)是app.json里配置的路径
        path: 'pages/yeles/yeles?orderid=' + that.data.da.id,
     success: function (res) {
	   //转发成功的回调
           console.log(res)
      if (res.errMsg == 'shareAppMessage:ok') {
		
      }
      },
      fail: function (res) {
	   //转发取消或失败的回调
           if (res.errMsg == 'shareAppMessage:fail cancel') {
             wx.showToast({
         	title: '转发取消',
            })
            } else if (res.errMsg == 'shareAppMessage:fail') {
          	wx.showToast({
           	  title: '转发失败',
         	})
       	     }
           }
       }
   }, 

  

用户在逻辑层定义了onShareAppMessage函数,用户才可以点击右上角的菜单分享

另外一种触发分享是button,<button  openType="share" > 定义这样一个属性为openType,值为share的按钮也可以触发分享

分享推荐:

商品分享带参:商品id和用户id

砍价分享:订单id

当时上传分享的时候入了个坑:

不止是分享,然后还有小程序本身,再上传的时候尽量把测试的console.log全部去掉。可能也是当时测试没细心,console一个字段报了个错,导致下面的流程没有走,其实把console去掉了什么事都没有了,

猜你喜欢

转载自www.cnblogs.com/naturl/p/9480608.html