小程序--分享功能

1 场景 点击自定义的分享按钮

2 解决 既可以点击整个item进入详情页,又可以点击分享按钮,出现的冒泡问题。

  出现的现象: 点击分享按钮时,分享的内容弹框出现,但是页面又跳进到商品的详情页。

button 按钮上要同时加上open-type='share'  catchtap = '方法名称'

 <button open-type="share" catchtap='share' class='shareBtn' data-name='share' id='{{item.id}}'></button>
  share() {
    
  },
  onShareAppMessage: function (res) {
    console.log(res) //res 中有from字段可判断点击的分享按钮来源
    if (res.target.dataset['name'] == 'share') {
      return {
        title: '有啥买啥',
        path: '/pages/goodDetail/goodDetail?goodId=' + res.target.id,
        success: function (res) {
        }
      }
    }
  },
原文地址:https://www.cnblogs.com/mengdiezhuangzhou/p/9705523.html