uniapp 触底加载分页

uniapp yekong 896℃

onLoad() {
        this.getdata();
    },
    onReachBottom() {
        this.getmore();
    },
    methods: {
        //加载更多
        getmore() {
            var that = this;
            that.page = that.page + 1;
            uni.showNavigationBarLoading();
            that.more = 'loading';
            let data = {
                customerGroupId: '',
                tenantId: '',
                companyId: '',
                page: this.page,
                rows: this.rows,
                sort: '',
                order: '',
                keyword: ''
            };
            this.$minApi
                .GetCustomerList(data)
                .then(res => {
                    uni.hideNavigationBarLoading();
                    console.log(res);
                    that.more = 'more';
                    if (res.code == 1) {
                        var data = res.data.rows;
                        if (!data || data.length == 0) {
                            that.more = 'noMore';
                        }
                        for (var i = 0; i < data.length; i++) {
                            that.list.push(data[i]);
                        }
                    } else {
                        uni.showToast({
                            title: res.msg,
                            duration: 2000,
                            icon: 'none'
                        });
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //加载第一页
        getdata() {
            let data = {
                customerGroupId: '',
                tenantId: '',
                companyId: '',
                page: this.page,
                rows: this.rows,
                sort: '',
                order: '',
                keyword: ''
            };
            this.page = 1;
            uni.showNavigationBarLoading();
            this.$minApi.GetCustomerList(data).then(res => {
                uni.hideNavigationBarLoading();
                if (res.code == 1) {
                    this.total = res.data.total;
                    this.list = res.data.rows;
                } else {
                    uni.showToast({
                        title: res.msg,
                        icon: 'none',
                        duration: 2000
                    });
                }
            });
        }
    }

如果是组件需要加载分页的话可以通过uniapp子组件监听触底 监听页面触底的方式来加载分页

喜欢 (3)