小程序分享链接

通过给 button 组件设置属性 open-type="share",可以在用户点击按钮后触发Page.onShareAppMessage事件。

<button class="share-button" open-type="share"></button>
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    console.log(e.from)    //转发事件来源 button:页面内转发按钮 menu:右上角转发菜单
    console.log(e.target)  //如果from值是button,则target是触发这次转发事件的button,否则为undefined
    console.log(webViewUrl)  //页面中包含web-view组件时,返回当前web-view的url
    let url = '/pages/home/detail?id='+this.data.dataId+'&from=share'
    return {
      title: '标题',
      path: url,
      imageUrl: '../../images/coverimage.jpg', //缩略图,如果不设置取系统默认截图
      success: function(res) {
        // 转发成功
      },
      fail: function(res) {
        // 转发失败
      }
    }
  },

猜你喜欢

转载自blog.csdn.net/watson2017/article/details/118541146