Bootstrap

uni上拉加载,下拉刷新

在pages.json中加入

     

   {
            "path": "pages/index/index",
            "style": {
                "enablePullDownRefresh": true
                "onReachBottomDistance": 150
            }
        },

在data函数中定义

total:null,

formData:{

        pageSize:10,//每页几条数据

        page:1,//第几页
}

定义加载数据的方法

getData(){

API.member(this.formData).then((res)=>{

        this.total = res.data.data.total

        //新数据push到列表中

        const newList = res.data.data.data

        this.List.push(...newList)

}else{

console.log('请求数据失败')

上拉到底触发,和生命周期同级

onReachBottom(){

        let allTotal = this.formData.page*this.form.pageSize

        if(allTotal <this.total){

        this.form.page++;

        this.getData()

}else{

console.log('221')

}

下拉刷新

  onPullDownRefresh () {
    this.list = []
    //调用获取数据方法
    this.getData()
    setTimeout(() => {
        //结束下拉刷新
      uni.stopPullDownRefresh ();
    }, 1000);
  },

每次回到页面调用

  onShow() { //没次回到页面都会调用下拉刷新
      uni.startPullDownRefresh()
  },
  onLoad() { //页面最开始调用
      uni.startPullDownRefresh()
  },

;