uni-app 下拉刷新

小小记录一下

(一) 下拉刷新

    <!-- page.json 中设置一下 -->
    "enablePullDownRefresh": true,
    <!-- 当前页处理下拉时候的事件 -->
    onPullDownRefresh(){
    },
    <!-- 处理完成后关闭下拉效果 -->
    uni.stopPullDownRefresh();
    
    setTimeout(function () {
        uni.stopPullDownRefresh();
    }, 2000);

  

(二) 上拉加载

    <!-- data 里自定义一个空数组 -->
    list: []

    <!-- 调接口的时候 用 ... 拼接 -->
    this.list.push(...data);

    <!-- 分页的时候直接 page++ 再调接口就好 -->
    onReachBottom() {
        if (!this.nomore) {
            this.page++;
            this.getData();
        }
    }

    <!-- 可以先用 if 判断下条件,然后再确定是否要加载(这样可以少请求接口,更方便) -->

  

原文地址:https://www.cnblogs.com/xiaoyaolang/p/13993238.html