微信小程序点击右上角胶囊分享动态获取title

刚又试了下,这种有点试方法有点复杂了

方法一:

wxml:(父级页面)

<view class="pageLi flex" catchtap="toInstitute" data-name="{{item.shop_name}}" data->

<image src='{{item.headimg}}' mode='aspectFill'></image>

<view class="pagePre sub">

<text class="tit f32">{{item.shop_name}}</text>

<view class="page_text flex">

<text wx:for="{{item.sports}}" wx:if="{{idx<4}}" wx:for-index="idx" wx:for-item="item2">{{item2.sport_name}}</text>

</view>

<text class="phone">联系电话:{{item.phone}}</text>

<text class="add">浏览:{{item.sort}}</text>

<text class="add">{{item.address}}</text>

</view>

</view>

wxjs:(父级页面)

toInstitute: function(e) {
    let share_title=e.currentTarget.dataset.name
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/newPage/institute/index?share_title=' + share_title + '&id=' + id
    })
  },

wxjs:(子页面)

data: {
    id: 0,
    shareTitle:''
},
onLoad: function (options) { 
    this.data.id = options.id
    this.data.shareTitle=options.share_title
    console.log(this.data.shareTitle)
    console.log(options.share_title)
}

/**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
    console.log(options.share_title)
    // 用户点击了“转发”按钮
    return {
      title: this.data.shareTitle
    }
  },

方法二:(简化法)当前页面的分享

wxml:

<view class="pageList f24">
    <view class="pageLi flex"  data- data-name="{{traininfo.shop_name}}">
        <image src='{{traininfo.headimg}}' mode='aspectFill'></image>
        <view class="pagePre sub">
            <text class="tit f32">{{traininfo.shop_name}}</text>
            <view class="page_text flex">
                  <text wx:for="{{sports}}" wx:if="{{idx<4}}" wx:for-index="idx"  wx:for-item="item2">{{item2.sport_name}}</text>
            </view>
            <text class="phone" data-phone="{{traininfo.phone}}" catchtap="tophone" >联系电话:{{traininfo.phone}}</text>
            <text class="add" catchtap="openMap" >{{traininfo.address}}</text>
        </view>
    </view>
</view>

wxjs:

data: {

shareTitleSub:''

},


onLoad: function () {   app.mylocation().then(function (res) { app.HTTP.post(app.URL.train_url, param, (res) => { that.data.shareTitleSub=res.traininfo.shop_name }) } onShareAppMessage: function (options) { console.log(options.share_title) // 用户点击了“转发”按钮 return { title: this.data.shareTitleSub } },