天天看點

uniapp - 觸底加載、下拉重新整理及關閉下拉重新整理

methods: {
  // 調用接口
  getStudyList(callBack){
    let params = {
      safeTypeId: this.safeTypeId,
      current: this.current
    }
    Home.studyData(params).then(res=>{
      this.total = res.data.total
      this.filter(res.data.records);
      this.contents = [...this.contents, ...res.data.records]
      // 關閉下拉重新整理回調函數
      callBack && callBack()
    })
  }
}
           
// 觸底加載
onReachBottom() {
  if(this.contents.length>=this.total){
    this.flag = true
  }else{
    this.current++
    this.getStudyList()
  }
},
// 下拉重新整理
onPullDownRefresh () {
  this.current = 1
  this.contents = []
  this.flag = false
  this.getStudyList(()=>{
    uni.stopPullDownRefresh();
  })
}
           

繼續閱讀