Small micro-channel program, enter the shared page, Home approach (with source code)

Micro-channel sharing applet page, click on the time of entry, there is no tab bar, if you want to return to the home page, you can add your own suspension of a Home button, so that you can return to the home page

The main page Code
js

Page({

  /**
   * 页面的初始数据: isshare = 0,表示不是从分享进入, isshare = 1 表示是从分享进入
   */
  data: {
    isshare: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    //可以在页面 onLoad 中去获取页面 url 中的参数( 下面 onShareAppMessage 函数中配置)
    if (options.isshare == 1) {
      console.log('是分享进入');
      this.setData({
        'isshare': options.isshare
      })
    }
    
  },

  /**
   * 用户点击右上角分享 (path 中配置了参数 isshare = 1,用来 onLoad 中判断是否用户从分享出去的页面点击进入)
   */
  onShareAppMessage: function () {
    return {
      title: '配置分享显示的标题',
      path: '/pages/home/project-detail/project-detail?isshare=1',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  
/**
  * 回到首页(分享的时候)
  */
  backHome: function () {
    wx.reLaunch({
      url: '/pages/home/home-index/home-index'
    })
  }
})

wxml

<view class='container'>
  页面主要内容
</view>

<!-- 回到首页(分享的时候显示) -->
<image wx:if="{{isshare}}" bindtap='backHome' class='d-back-home' src='http://cdn.xcx.pemarket.com.cn/icon-Return%20to%20the%20home%20page.png' lazy-load></image>

wxss

/* 回到首页,固定定位,悬浮 */
.d-back-home {
  position: fixed;
  width: 96rpx;
  height: 96rpx;
  right: 30rpx;
  bottom: 166rpx;
  z-index: 10000;
}

Guess you like

Origin blog.csdn.net/qq_42363090/article/details/93206750