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()
        }
      },
    })
    
  • 相关阅读:
    2019年8月20日 item系列
    变量和字符
    python命名规则
    五大常用算法之贪心算法
    过河卒
    组成三位数
    编码问题
    FatMouse' Trade
    A Boring Game
    螺旋矩阵
  • 原文地址:https://www.cnblogs.com/cckui/p/10856396.html
Copyright © 2011-2022 走看看