zoukankan      html  css  js  c++  java
  • 微信小程序之判断页面来源

    1. 对非首页,使用 getCurrentPages 函数获取当前页面栈

    onLoad: function (options) {
        let pages = getCurrentPages()
        if (pages.length >= 2) {
            let prevpage = pages[pages.length - 2]
            console.log(prevpage.route)
        }
    },
    

    2. 对首页,通过在 data 中定义标记变量,判断页面是否从其他页面返回

    
    Page({
      data: {
        isClose: true, //判断当前页面是打开还是返回页  
        list: [], 
        page: 0
      },
    
      onLoad: function() { 
        this.getList()
      },
     
      getList () {
          // ...
      },
      
      goDetail (e) { 
        this.setData({
          isClose: false
        })
        wx.navigateTo({
          url: `/pages/detail/detail`,
        }) 
      },
     
      onShow: function () {
        console.log(this.data.isClose)
    
        if (!this.data.isClose) {
          this.setData({
            page: 2, // 页码
            isClose: true,
            list: []
          })
          this.getList()
        }
      },
    })
    
  • 相关阅读:
    2016.7.31整机升级计划
    UVa 1588
    UVa1587
    Jzoj4714 公约数
    Jzoj4714 公约数
    Jzoj4713 A
    Jzoj4713 A
    Jzoj4711 Binary
    Jzoj4711 Binary
    Jzoj4710 Value
  • 原文地址:https://www.cnblogs.com/cckui/p/10856396.html
Copyright © 2011-2022 走看看