1. 程式人生 > >微信小程式之分享頁面如何返回首頁

微信小程式之分享頁面如何返回首頁

<!--index.wxml-->
<view class="container">
<text>我是首頁</text>
  <button bindtap='goLogs'>go logsPage</button>
</view>

const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  //事件處理函式
  goLogs: function() {
    wx.navigateTo({
      url: '/pages/logs/logs'
    })
  },
  onLoad: function (options) {
    console.log(options)
    if (options.share_query){
      wx.showLoading({
        title: '我是從分享頁面進入的',
      })

      setTimeout(function () {
        wx.hideLoading()
        wx.navigateTo({
          url: '/pages/logs/logs',
        })
      }, 2000)

    
    }

    }
  
})
<!--logs.wxml-->
<view class="container log-list">
  <block wx:for="{{logs}}" wx:for-item="log">
    <text class="log-item">{{index + 1}}. {{log}}</text>
  </block>
</view>
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  //事件處理函式
  goLogs: function() {
    wx.navigateTo({
      url: '/pages/logs/logs'
    })
  },
  onLoad: function (options) {
    console.log(options)
    //判斷是否分享進入
    if (options.share_query){
      wx.showLoading({
        title: '我是從分享頁面進入的',
      })

      setTimeout(function () {
        wx.hideLoading()
        wx.navigateTo({
          url: '/pages/logs/logs',
        })
      }, 2000)

    
    }

    }
  
})