+
80
-

小程序怎么获取用户通过share按钮分享还是右上角三个点分享出去的?

小程序怎么获取用户通过share按钮分享还是右上角三个点分享出去的?


网友回复

+
0
-

通过 res.from 来判断用户是否通过按钮分享,如果是,则表示用户通过内部share按钮分享。

Page({
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 用户通过内部自定义share按钮分享
      console.log('User shared through button');
    }
if (res.from === 'menu') {
      // 用户通过右上角转发按钮分享
      console.log('User shared through button');
    }

    return {
      title: '分享标题',
      path: '/pages/index/index',
      imageUrl: '/images/share-image.jpg',
    };
  }
});

官方文档介绍如下:

6555672b0deaa.png

我知道答案,我要回答