剛又試了下,這種有點試方法有點復雜了
方法一:
wxml:(父級頁面)
<view class="pageLi flex" catchtap="toInstitute" data-name="{{item.shop_name}}" data-id="{{item.id}}">
<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-id="{{item.id}}" 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" style="color:#04B59A;text-decoration: underline;">聯系電話:{{traininfo.phone}}</text> <text class="add" catchtap="openMap" style="color:#04B59A;text-decoration: underline;">{{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 } },