1.分享和返回
1.1 分享代码,设置了分享的标题,以及跳转的路径等。对路径做了参数处理,以便区分出用户的来源。为什么要区分用户来源呢,因为小程序的分享页面进入后没有返回主页的按钮。所以单独做区分,当用户来自分享时,显示一个悬浮的返回首页的图标。
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
return {
title: this.data.postData.title,
path: '/pages/post-detail/post-detail?id=' + this.data.id + "&title=" + 'AspNetCore小程序' + "&share=1"
}
},
1.2 显示主页图标浮动按钮
<!-- 回到首页(如果来自分享连接,显示返回主页图标) -->
<image wx:if="{{share}}" bindtap='onBackHome' class='back-home' src='/img/home-page.png' lazy-load></image>
1.3 点击事件处理
/**
* 回到首页(分享的时候)
*/
onBackHome: function () {
wx.reLaunch({
url: '/pages/index/index?share=1"'
})
},