小程序上拉加載下拉刷新

<view class="container">
    <view  wx:if="{{isUpper}}" class="lower-con">數據已更新</view>
     <!-- 問題展示開始 -->
    <block wx:for="{{lists}}" wx:key="idx">
     
    </block>
    <!-- 問題展示結束 -->
    <view wx:if="{{isLower}}" class="lower-con">沒有多餘的消息了</view>
</view>
Page({
  data: {
    lists:[],
    current: 1,
    isUpper: false,
    isLower: false
  },
    /**
   * 生命週期函數--監聽頁面加載
   */
  onLoad: function (options) {
    this.getData()
  },
  //獲取數據
  getData(){
      const data = {}
      const _this = this
        app.POST('lists', data, function (res) {
          if (res.data.errno === 0) {
            if (_this.data.current > 1 && res.data.data.data.length === 0) {
              _this.setData({
                isLower: true
              })
            } else {
              _this.setData({
                lists: res.data.data.data
              })
            }
          } else {
            wx.showToast({
              title: '網絡錯誤',
              icon: 'warn',
              duration: 2000
            })
          }
        })
  },
   /**
   * 頁面相關事件處理函數--監聽用戶下拉動作
   */
  onPullDownRefresh: function () {
    const _this = this
    if (_this.data.current == 1){
      var timeIn = setTimeout(function () {
        _this.setData({
          isUpper: true
        })
      }, 3000)
      var timeOut = setTimeout(function () {
        _this.setData({
          isUpper: false
        })
      }, 6000)
    }else{
      _this.setData({
        current: _this.data.current - 1
      })
      this.getData()
    }
  },

  /**
   * 頁面上拉觸底事件的處理函數
   */
  onReachBottom: function () {
    this.setData({
      current: this.data.current + 1
    })
    this.getData()
    const _this = this
    var timeOut = setTimeout(function () {
      _this.setData({
        isLower: false
      })
    }, 6000)
  }
})
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章