小程序开放平台

文档中心
暂无目录

转发

更新时间:2025-12-22 20:45:47

页面内唤起分享

通过给

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

分享的类型

开发者可以基于 button 组件配置 data-share-type 来唤起不同的分享入口,不同分享入口的对应关系如下:

分享类型
data-share-type
最低版本
小红书站内分享normal3.28.0
朋友圈(微信)分享shareTimeline3.28.0
微信群组分享shareChat3.28.0

代码示例:

带 shareTicket 的分享

客户端 > 8.57, 基础库 > 3.108.x 以后的版本,分享出去的链接将包含 shareTicket 信息,开发者可以通过 xhs.getShareInfo 获取到分享者信息:

代码示例:

  App({ 
     onLaunch(opts, data) {
       console.log('App:onLaunch========', opts.shareTicket);
     }
  })
  
  Page({
  getShareInfo() {
    if (!this.data.shareTicket) {
      xhs.showToast({ title: '请先获取 shareTicket' });
      return;
    }

    let _this = this;

    xhs.getShareInfo({ 
      shareTicket: _this.data.shareTicket,
      success(res) {
        console.log('getShareInfo success', res);
        _this.setData({ shareInfo: '获取 shareInfo 信息成功:' + JSON.stringify(res) });
      },
      fail(err) {
        console.log('getShareInfo fail', err);
        _this.setData({ shareInfo: '获取 shareInfo 信息失败:' + JSON.stringify(err) });
      }
    });
  }
  })

tips

  • data-share-type 默认是 normal (站内分享)