微信小程序判断页面是否从其他页面返回

在 data 中自定义一个标记变量,在onLoad里

Page({
  data: {
    isNewOpen: true, //判断当前页面是新打开还是从其他页面返回  
    list: [], 
    page: 0
  },

  onLoad: function() { 
    this.getList()
  },
 
  getList () {
      // ...
  },
  
  goDetail (e) { 
    this.setData({
      isNewOpen: false
    })
    wx.navigateTo({
      url: `/pages/detail/detail`,
    }) 
  },
 
  onShow: function () {if (!this.data.isNewOpen) {
      this.setData({
        page: 2, // 页码
        isClose: true,
        list: []
      })
      this.getList()
    }
  },
})

猜你喜欢

转载自www.cnblogs.com/djjlovedjj/p/11124425.html
今日推荐