实现分页加载,加载更多(按钮类型),滚动加载的方式
Posted hudunyu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现分页加载,加载更多(按钮类型),滚动加载的方式相关的知识,希望对你有一定的参考价值。
基于vue语法
分页加载(vue+element -ui)
<template> <div> <el-pagination class="pagination" background layout="prev, pager, next" :pageSize="pageSize" :total="total" @current-change="handleChange" > </el-pagination> </div> </template> <script> import { Pagination, Button } from "element-ui"; //局部引入分页组件 export default { name: "demo", components: { [Pagination.name]: Pagination, }, data() { return { pageSize: 3, pageNum: 1, total: 0, }; }, mounted() { this.getOrderList(); }, methods: { getOrderList() { this.axios .get("/orders", { params: { pageSize: this.pageSize, pageNum: this.pageNum, }, }) .then((res) => { this.list = res.list; this.total = res.total; this.loading = false; }) .catch(() => { this.loading = false; }); }, //分页器分页 handleChange(pageNum) { this.pageNum = pageNum; this.getOrderList(); }, }, }; </script> <style></style>
加载更多
点击按钮加载更多,始终一屏显示,加载数据拼接在原数据后面!
<template> <div> <el-button type="primary" :loading="loading" @click="loadMore" >加载更多</el-button > </div> </template> <script> import { Button } from "element-ui"; //局部引入分页组件 export default { name: "demo", components: { [Button.name]: Button, }, data() { return { pageSize: 3, pageNum: 1, }; }, mounted() { this.getOrderList(); }, methods: { getOrderList() { this.axios .get("/orders", { params: { pageSize: this.pageSize, pageNum: this.pageNum, }, }) .then((res) => { this.list = this.list.concat(res.list);//拼接原数据 this.total = res.total; this.loading = false; }) .catch(() => { this.loading = false; }); }, loadMore() { this.getOrderList(); }, }, }; </script> <style></style>
滚动加载数据
1.使用插件 vue-infinite-scroll
2.使用插件better-scroll
可查看相关文档哈
以上是关于实现分页加载,加载更多(按钮类型),滚动加载的方式的主要内容,如果未能解决你的问题,请参考以下文章