收藏
回答

获取onShareAppMessage分享参数?

data() {

return {

//1 轮播图数据列表

swiperList: [],

//2 商品数据列表

goodsList: [],

//推广参数

id: '',

share: {

shareId: '10000', //推广用户ID

title: '移动业务推广',

path: '/pages/home/home?id=1000', // 全局分享的路径,比如 首页

posterImg: 'https://www.fslygo.com:8001/mobile/2023/05/25/poster_20230525235210A007.jpg'

}

};

},

// 1.发送给朋友

onShareAppMessage(res) {

//console.log('onShareAppMessage',res)

return {

title: this.share.title,

path: this.share.path,

query: 'id=' + this.share.shareId,

imageUrl: this.share.posterImg,

}

},

//2.分享到朋友圈

onShareTimeline(res) {

//console.log('onShareTimeline',res)

return {

title: this.share.title,

path: this.share.path,

query: 'id=' + this.share.shareId,

imageUrl: this.share.posterImg,

}

},

回答关注问题邀请回答
收藏

3 个回答

  • 睡前原谅一切
    睡前原谅一切
    2023-05-30
    // 1.发送给朋友
    onShareAppMessage(res) {
      return {
        title: this.share.title,
        path: `${this.share.path}?id=${this.share.shareId}`,
        imageUrl: this.share.posterImg,
      }
    },
    //2.分享到朋友圈, 分享朋友圈没有path
    onShareTimeline(res) {
      return {
        title: this.share.title,
        query: `id=${this.share.shareId}`,
        imageUrl: this.share.posterImg,
      }
    }
    


    // 获取参数 app.js
    onLaunch(options) {
      this.globalData.query = options.query || {}
      if (options.referrerInfo) {
         this.globalData.query = Object.assign(this.globalData.query, options.referrerInfo.extraData)
      }
    },
    onShow(options) {
      this.globalData.query = options.query || {}
      if (options.referrerInfo) {
         this.globalData.query = Object.assign(this.globalData.query, options.referrerInfo.extraData)
      }
    },
    globalData: {
      query: {}
    }
    


    // 页面js
    onLoad(options) {
       // 先从上个页面获取,再从app.js里获取,都没获取到给个空字符串做保护。
       this.setData({
         shareId: options.id || app.globalData.query.id || ''
       })
    }
    


    2023-05-30
    有用 1
    回复
  • 大熊
    大熊
    2023-05-30

    参数拼在链接后面

    2023-05-30
    有用 1
    回复
  • 大山
    大山
    2023-05-30

    仔细看一下文档说明,转发好友没有 query 这个参数,参数直接跟在 path 上。

    2023-05-30
    有用 1
    回复
登录 后发表内容