uni-app上划加载分页效果

html部分:

// 列表组件
<dataList ref="course" :courseList="courseList" />
// 分页加载更多组件(该组件要去插件市场安装)
<uni-load-more v-if="courseList.length > 5" :contentText="contentText" :status="status" />

js部分:

<script>
    // 引入列表组件(自己手写)
    import dataList from './components/dataList'
    export default {
        components: {
            dataList
        },
        data() {
            status: 'more',
            contentText: {
                contentdown: "加载更多",
            contentrefresh: "正在加载...",
            contentnomore: "已经到底了哟QAQ~"
            },
            courseList: [],
            total: 0,
        pagination: {
        current: 1,
        size: 5
        },
        },
        onShow() {
        this.getData()
    },
    onReachBottom() {
        const { total } = this;
        const { current, size } = this.pagination;
        if (total > (current * size)) {
        this.status = 'loading';
        this.pagination.current++;
        this.getData(true);
        } else {
        this.status = 'noMore';
        }
    },
    methods: {
             async getData(more) {
        let res = await uni.service.home.getCourseList(this.pagination)
        if (res.code === 200) {
                    if (more) {
                        this.courseList = this.courseList.concat(res.data.records);
                    } else {
                        this.courseList = res.data.records
                    }
                        this.total = res.data.total;
            this.status = 'more';
                }
            }
    }
    }
</script>                                

 

posted @ 2021-08-03 09:58  王浅浅  阅读(627)  评论(0编辑  收藏  举报