vue 分页插件
有个小问题就是最多显示3个分页,可以手动改一下配置参数就好。直接代码:
<template>
<div class="pageination_align">
<div class="pageination" v-if="pageinationTotal">
<div @click="pageUp(0)" class="pagination_page" :class="startDisabled?'disabled':''">首页</div>
<div @click="pageUp(1)" class="pagination_page" :class="startDisabled?'disabled':''"><</div>
<div class="pagination_page" :class="item==pageinationCurrentPage?'pagination_page_active':''"
v-for="item in pageinationLength" @click="jump(item)">
{{item}}
</div>
<div @click="pageDown(1)" class="pagination_page" :class="endDisabled?'disabled':''">></div>
<div @click="pageDown(0)" class="pagination_page pagination_page_right" :class="endDisabled?'disabled':''">尾页
</div>
</div>
</div>
</template> <script>
export default {
name: 'pageination',
props: ['total', 'size', 'page', 'changge', 'isUrl'],
data(){
return {
pageinationTotal: this.total,//总条目数
pageinationSize: this.size ? this.size : 10,//每页显示条目个数
pageinationLength: [],
pageinationCurrentPage: this.page ? this.page : 1,//当前页数默认1
pageinationPage: 0,//可分页数
startDisabled: true,//是否可以点击首页上一页
endDisabled: true,//是否可以点击尾页下一页
pageChangge: this.changge,//修改方法
pageIsUrl: this.isUrl ? true : false,//是否开启修改url
}
},
methods: {
jump(item){
this.pageinationCurrentPage = item;
this.pagers();
this.pageChangge(this.pageinationCurrentPage);
},//跳转页码
pagers(){
//可分页数
this.pageinationPage = Math.ceil(this.pageinationTotal / this.pageinationSize); //url修改
if (this.pageIsUrl) {
this.$router.replace({
path: this.$route.path,
query: {
page: this.pageinationCurrentPage,
}
});
}
//是否可以点击上一页首页
this.startDisabled = this.pageinationCurrentPage != 1 ? false : true;
//是否可以点击下一页尾页
this.endDisabled = this.pageinationCurrentPage != this.pageinationPage ? false : true;
if(this.pageinationPage==0) this.endDisabled=true; //重置
this.pageinationLength = [];
//开始页码1
let start = this.pageinationCurrentPage - 3 > 1 ? this.pageinationCurrentPage - 3 : 1;
//当前页码减去开始页码得到差
let interval = this.pageinationCurrentPage - start;
//最多4个页码,总页码减去interval 得到end要显示的数量+
let end = (3 - interval) < this.pageinationPage ? (3 - interval) : this.pageinationPage;
//最末页码减开始页码小于8
if ((end - start) != 8) {
//最末页码加上与不足4页的数量,数量不得大于总页数
end = end + (3 - (end - start)) < this.pageinationPage ? end + (3 - (end - start)) : this.pageinationPage;
//最末页码加上但是还不够9页,进行开始页码追加,开始页码不得小于1
if ((end - start) != 3) {
start = (end - 3) > 1 ? (end - 3) : 1;
}
}
for (let i = start; i <= end; i++) {
this.pageinationLength.push(i);
}
},//计算分页显示的数字
pageUp(state){
if (this.startDisabled)return;
if (this.pageinationCurrentPage - 1 != 0 && state == 1) {
this.jump(this.pageinationCurrentPage - 1);
} else {
this.jump(1);
} },//上一页跟首页 state=1是上一页 state=0是首页
pageDown(state){
if (this.endDisabled)return;
if (this.pageinationCurrentPage + 1 != this.pageinationPage && state == 1) {
this.jump(this.pageinationCurrentPage + 1);
} else {
this.jump(this.pageinationPage);
} },// state=1是下一页 state=0是尾页
pageCurrentChange(){
this.pageChangge(this.pageinationCurrentPage);
this.pagers();
}
},
created(){
this.pageCurrentChange();
},
watch: {
total: function (val, oldVal) {
this.pageinationTotal = val;
this.pagers();
},
page:function (val, oldVal) {
this.pageinationCurrentPage = val;
this.pagers();
}
}
}
</script> <style scoped>
.pageination_align{
text-align: center
}
.pageination {
color: #48576a;
font-size: 12px;
display: inline-block;
user-select: none;
} .pagination_page {
padding: 0 4px;
border: 1px solid #d1dbe5;
border-right: 0;
background: #fff;
font-size: 13px;
min-width: 28px;
height: 28px;
line-height: 28px;
cursor: pointer;
box-sizing: border-box;
text-align: center;
float: left;
} .pagination_page_right {
border-right: 1px solid #d1dbe5;
} .pagination_page:hover {
color: #ED4D53;
} .disabled {
color: #e4e4e4 !important;
background-color: #fff;
cursor: not-allowed;
} .pagination_page_active {
border-color: #ED4D53;
background-color: #ED4D53;
color: #fff !important;;
cursor: default;
}
</style>
vue 分页插件的更多相关文章
- 基于vue的分页插件
相信大家用过很多jquery的分页插件,那这次就用一用基于vue的分页插件. 这里的环境用的是springboot 首先要引入pagehelper的jar文件,版本是1.2.3,配置文件也需要配置一下 ...
- vue中的自定义分页插件组件
介绍一下,已经有很多的vue分页的组件了,大家都是大同小易,那么我就结合自身的使用,写出了一片文章 首先在新建一个分页模块 在模块中引入相应的代码,(内有详细的注释) template中 <di ...
- vue各种插件汇总
https://blog.csdn.net/wh8_2011/article/details/80497620(copy) Vue是什么? Vue.js(读音 /vjuː/, 类似于 view) 是一 ...
- vue常用插件汇总
UI-框架element - 饿了么出品的Vue2的web UI工具套件 mint-ui - Vue 2的移动UI元素 iview - 基于 Vuejs 的开源 UI 组件库 Keen-UI - 轻量 ...
- 基于VUE2.0的分页插件(很好用,很简单)
基于jQuery的分页插件很多,今天分享一下基于Vue的分页插件pagination.js,该插件使用用感觉很不错,简单不复杂,现将个人使用过程中的方法与遇到的问题以及实例分享出来. 下载解压的主要目 ...
- Vue2.0 分页插件pagination使用详细说明
Vue2.0 分页pagination使用 插件下载地址:Vue_Pagination 插件描述:基于jQuery的分页插件大家都用过很多了吧,今天分享一下基于Vue的分页插件pagination.j ...
- vue 常用插件,保存
UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 mint-ui- Vue 2的移动UI元素 iview- 基于 Vuejs 的开源 UI ...
- Mybatis Plus 3.4版本之后分页插件的变化
一.MybatisPlusInterceptor 从Mybatis Plus 3.4.0版本开始,不再使用旧版本的PaginationInterceptor ,而是使用MybatisPlusInter ...
- MVC如何使用开源分页插件shenniu.pager.js
最近比较忙,前期忙公司手机端接口项目,各种开发+调试+发布现在几乎上线无问题了:虽然公司项目忙不过在期间抽空做了两件个人觉得有意义的事情,一者使用aspnetcore开发了个人线上项目(要说线上其实只 ...
随机推荐
- 洛谷P3740 [HAOI2014]贴海报
题目描述 Bytetown城市要进行市长竞选,所有的选民可以畅所欲言地对竞选市长的候选人发表言论.为了统一管理,城市委员会为选民准备了一个张贴海报的electoral墙. 张贴规则如下: electo ...
- STM32自动生成精美图案
http://note.youdao.com/noteshare?id=65f237225624d22fe18f4aaaeec8db07
- python练习1--用户登入
python版本为python3.51.要求 1)输入用户名密码 2)认证成功后显示欢迎信息 3)输错三次后锁定 2.需求分析 1)用户信息存储在文件中(login/config/user_login ...
- redis服务启动脚本
/etc/rc.d/init.d/redis #!/bin/sh# chkconfig: 2345 80 90 # description: Start and Stop redis REDISPOR ...
- AbstractTransactionalJUnit4SpringContextTests事务回滚
在单元测试中继承AbstractTransactionalJUnit4SpringContextTests类的 时候,会默认事务回滚. 需要照常执行的话,在执行的测试方法上添加@Rollback(fa ...
- NAIPC2018-K-Zoning Houses
题目描述 Given a registry of all houses in your state or province, you would like to know the minimum si ...
- 使用inline-block,使前面img,后面空div居中显示在一行后,导致当div中有内容时,div下移问题
.pro_li img,.pro_sm{display: inline-block; *display:inline;*zoom:1;vertical-align: middle ;} 解决方法:使用 ...
- 吐泡泡(2018年全国多校算法寒假训练营练习比赛(第二场)+栈模拟)+Plug-in(codeforces81A+栈模拟)
吐泡泡题目链接:https://www.nowcoder.com/acm/contest/74/A 题目: 思路: 这种题目当初卡了我很久,今天早训时遇到一个一样得题,一眼就想到用栈模拟,就又回来把这 ...
- HDU 1059 Dividing (dp)
题目链接 Problem Description Marsha and Bill own a collection of marbles. They want to split the collect ...
- HDU 2319 Card Trick (模拟)
题目链接 Problem Description The magician shuffles a small pack of cards, holds it face down and perform ...