vue分页

news/2024/7/9 23:55:46 标签: 分页, vue分页, vue后台分页, vue如何分页, vue

先看看效果图

在这里插入图片描述

首先你需要有一个前端的html分页

<!-- 分页 -->
                            <ul class="pagination" style="display: flex;justify-content: center;" id="paginationUl">
                                <li><a href="#" @click="firstPage"><<</a></li>
                                <li><a href="#" class="demo-pli-arrow-left" @click="prePage"></a></li>
                                <li v-for="n in pageLoopEnd"><a href="#" @click="clickPage(n+startPage-1)">{{n+startPage-1}}</a>
                                </li>
                                <li><a href="#" class="demo-pli-arrow-right" @click="nextPage"></a></li>
                                <li><a href="#" class="" @click="latestPage">>></a></li>
                                <li><a href="#" class="">2</a></li>
                                <li style="line-height: 33px;font-size: 12px;height: 33px;padding: 0 3px;background-color: #414a59;border-radius: 3px;">跳至<input type="text" style="width: 25px;height: 20px;border-radius: 3px;background-color: #36383c;color: #fefefe;border: none;text-align: center;margin: 0 3px;" value=""></li>
                            </ul>

在data定义分页数据

在这里插入图片描述

//分页数据定义--start
            currentPage: 1,
            totalPage: 1,
            startPage: 1,
            endPage: 1,
            pageSize: 10,
            //loop页数
            pageLoopEnd:5,
            //分页相关数据定义--end

然后就可以获取数据了

methods:{
// 获取事件列表数据
            getEventListData: function () {
                var _this = this;
                axios.get('接口地址', {
                    params: {//参数
                        "size": _this.pageSize,
                        "current": _this.currentPage
                    }
                }).then(function (rd) {
                	rd = rd.data;
                    //赋值分页数据
                    _this.currentPage = rd.data.current;
                    _this.totalPage = rd.data.pages;
                    if(_this.totalPage < 6){
                        _this.pageLoopEnd = _this.totalPage;
                    }else{
                        _this.pageLoopEnd = 5;
                    }
                    //初始化分页
                    _this.initPaging();
                }).catch(function (error) {
                    console.log(error);
                })
            },
            //初始化分页
            initPaging: function () {
                var _this = this;
                if (_this.currentPage <= 3) {
                    _this.startPage = 1;
                } else {
                    _this.startPage = _this.currentPage - 2;
                    if (_this.startPage > _this.totalPage - 4) {
                        _this.startPage = _this.totalPage - 4;
                    }
                }
            },
             //点击具体的分页
            clickPage: function (currentPage) {
                var _this = this;
                _this.currentPage = currentPage;
                _this.getEventListData();
            },
            //跳到第一页
            firstPage: function () {
                var _this = this;
                _this.currentPage = 1;
                _this.getEventListData();
            },
            //前一页
            prePage: function () {
                var _this = this;
                _this.currentPage = _this.currentPage - 1;
                if (_this.currentPage < 1) {
                    _this.currentPage = 1;
                    alert("已经是第一页了.")
                }
                _this.getEventListData();
            },
            //后一页
            nextPage: function () {
                var _this = this;
                _this.currentPage = _this.currentPage + 1;
                if (_this.currentPage > _this.totalPage) {
                    _this.currentPage = _this.totalPage;
                    alert("已经是最后一页了.")
                }
                _this.getEventListData();
            },
            //跳到最后一页
            latestPage: function () {
              var _this = this;
                _this.currentPage = _this.totalPage;
                _this.getEventListData();
            },
},
mounted:function (){//初始化
	this.initPage();
}

一套打完收工


http://www.niftyadmin.cn/n/797558.html

相关文章

suse 内核编译安装_Linux 内核升级

有时候需要在安装 docker 的时候&#xff0c;系统内核不够&#xff0c;需要升级到内核版本多少以上&#xff0c;可以用 uname -r 查看。用过 k8s 的同学应该知道&#xff0c;有时候在kubernetes集群中centos7.5低版本的内核中会出现一下很让人恼火的BUG&#xff0c;时不时来一下…

JS Excel传参导出、ajax传参导出Excel

在这之前尝试了好几种的方法都不行&#xff0c;主要是因为参数拼不上URL所以导致不成功 var xhr new XMLHttpRequest();xhr.open(get, http://localhost:8080/user/export, true);xhr.responseType blob;xhr.setRequestHeader(Content-Type, application/json;charsetutf-8)…

python025

re模块re模块是pyhon中的提供的一套关于处理正则表达式的模块.核心功能有四个:1.findall 查找所有.返回listimport relstre.findall("m","mai le fo len,mai ni mei!")print(lst) #结果:[m, m, m]lstre.findall(r"\d","5点之前.你要给我50…

js导入Excel、ajax导入Excel、Excel导入、Excel导入数据库

这是通过表单上传的方式 HTML <div class"input-group-wrap"><div class"input-group"><button filter"main-sjcl" class"btn btn-dark btn-labeled" style"float:left;"><i class"pli-down-4&…

时间戳的差,时间戳转换时分秒,时分秒格式化

function eventProcessNodeTimeComputed (a, b) {let sdate new Date(a);//结束时间let now new Date(b);//开始时间let endTimesdate.getTime();//结束时间let startTimenow.getTime();//开始时间let timeDiff endTime - startTime;let hours parseInt((timeDiff % (1000 …

IDEA上传文件到服务器、IDEA实现xshell功能、xshell、IDEA上传文件

1.在IDEA配置服务器账户、密码 2.配置文件路径 3.检测是否成功 4.把需要上传的文件上传到服务器 5.查看是否上传成功

python素数算法while_素数判断算法(基于python实现)

素数是只能被1与自身整除的数&#xff0c;根据定义&#xff0c;我们可以实现第一种算法。算法一&#xff1a;defisprime(n):if n < 2: returnFalsefor i in range(2,int(math.sqrt(n))1):if n % i 0:returnFalsereturn True任意一个合数都可分解为素数因子的乘积&#xff0c…

vue拼接html中onclick的触发方式,vue中的onclick,vue触发onclick,vue拼接html

1.首先你有一段拼接的html代码 let conten<button οnclick"come()">点我</button>;2.然后你需要在methods中有一个函数 methods:{come:function(){alert(你好&#xff0c;再见&#xff01;)}, }3.下一步就是连接起桥梁的关键点 created(){let _thist…