vue的分页组件
<template>
<div class="page-nav">
<div class="page-btn-wrap">
<span class="prev"
v-bind:class="{ disabled: currPage==1 }"
v-on:click="pagePrev"
>
上页
</span>
<span class="item
"v-bind:class="{ active: item==currPage }"
v-for="(item,index) in list"
:key="index"
v-on:click="pageTo(item)"
>
{{item}}
</span>
<span class="next"
v-bind:class="{ disabled: currPage==totalPage }"
v-on:click="pageNext"
>
下页
</span>
</div> </div>
</template> <script >
export default {
name:"page",
data(){
return{ sideNum:2, //显示页面按钮的一半,向下取整
currPage:1, //当前页面
totalPage:0, //需要分的页数, 例如有30条数据,每页为10条,则需要三页
list:[] }
}, props:{
"total":{
type: Number,
default:0
},
"pagesize":{
type:Number,
default:10,
},
"showPage":{
type:Number,
default:5
},
"pagenum":{
type:Number,
default:1
}
},
methods:{
getOffetSize:function(){
var that = this;
var start = 1;
var end = that.showPage;
if(that.totalPage < that.showPage) {
return {
start: 1,
end: this.totalPage
}
}
start = that.currPage - that.sideNum;
end = that.currPage + that.sideNum; if(start <= 1) {
start = 1;
end = that.showPage;
}
if(end >= that.totalPage) {
end = that.totalPage;
start = that.totalPage - 2 * that.sideNum;
} return {
start: start,
end: end
}
},
layout:function(){
//得到开始和结束
var that = this;
var list = [];
var opt = that.getOffetSize();
for(var i = opt.start ; i <= opt.end ; i++){
list.push(i);
}
that.list = list;
},
pageTo:function(pageNum){
var that = this;
that.currPage = pageNum;
that.layoutEmit();
},
pagePrev:function(){
var that = this;
var pageNum = that.currPage - 1; if(pageNum < 1){
return;
} that.currPage = pageNum;
that.layoutEmit();
},
pageNext:function(){
var that = this;
var pageNum = that.currPage + 1; if(pageNum > that.totalPage){
return;
}
that.currPage = pageNum;
that.layoutEmit();
},
layoutEmit(){
var that = this;
that.layout();
that.$emit("pagec",that.currPage);
}
},
watch:{
"total":function(newa,oldb){
var that = this;
that.currPage = 1;
console.log(newa,oldb);
that.totalPage = Math.ceil(newa / that.pagesize);
that.layout(); },
"pagenum":function(newa,oldb){
this.currPage = newa;
}
},
mounted:function(){
var that = this;
that.pagesize = that.pagesize || 10;
that.sildeNum = Math.floor(that.showPage / 2);
that.totalPage = Math.ceil(that.total / that.pagesize); that.layout(); }
}
</script> <style type="text/css" lang="less">
.page-nav{
.page-btn-wrap{
span{
display: inline-block;
width: 80px;
height: 26px;
line-height: 26px;
text-align: center;
border: 1px solid #ccc;
cursor: pointer;
}
span.prev,span.next{
width: 120px;
}
span.active{
background: #0099FF;
}
span.disabled{
background: #ccc;
}
}
}
</style>
使用
<page-btn
v-on:pagec="pagec"
:total="total"
:pagesize='opt.pagesize'
:pagenum='opt.pagenum'
></page-btn>

vue的分页组件的更多相关文章
- 基于Vue封装分页组件
使用Vue做双向绑定的时候,可能经常会用到分页功能 接下来我们来封装一个分页组件 先定义样式文件 pagination.css ul, li { margin: 0px; padding: 0px;} ...
- 基于iview 封装一个vue 表格分页组件
iview 是一个支持中大型项目的后台管理系统ui组件库,相对于一个后台管理系统的表格来说分页十分常见的 iview是一个基于vue的ui组件库,其中的iview-admin是一个已经为我们搭好的后天 ...
- vue 封装分页组件
分页 一般都是调接口, 接口为这种格式 {code: 0, msg: "success",…} code:0 data:{ content:[{content: "11& ...
- semantic、vue 使用分页组件和日历插件
最近正在试试semantic-ui,结合了vue,这里忍不住吐槽semantic和vue的友好度简直不忍直视,不过既然用了,这里就分享几个用到的插件了 1.分页组件(基于vue) var pageCo ...
- vue 自定义分页组件
vue2.5自定义分页组件,可设置每页显示条数,带跳转框直接跳转到相应页面 Pagination.vue 效果如下图: all: small(只显示数字和上一页和下一页): html <temp ...
- vue自定义分页组件---切图网
vue2.5自定义分页组件 Pagination.vue,可设置每页显示条数,带跳转框直接跳转到相应页面,亲测有用.目前很多框架自带有分页组件比如elementUI,不过在面对一个拿到PSD稿,然后重 ...
- vue封装分页组件
element提供的分页是已经封装好的组件,在这里再次封装是为了避免每个用到分页的页面点击跳转时都要写一遍跳转请求 分页组件 <!--分页组件--> <template> &l ...
- vue element-ui 分页组件封装
<template> <el-pagination @size-change="handleSizeChange" @current-change="h ...
- vue实现分页组件
创建pagination.vue /* * 所需参数 * total Number 总页数 * current Number 当前页面下标 * pageSize Number 页面显示条数 * siz ...
随机推荐
- Docker学习之——Node.js+MongoDB+Nginx环境搭建(一)
最近在学习Node.js相关知识,在环境搭建上耗费了不少功夫,故此把这个过程写下来同大家分享一下,今天我先来介绍一下Docker,有很多人都写过相关知识,还有一些教程,在此我只想写一下,我的学习过程中 ...
- Linux环境变量与文件查找
作业: 找出/etc目录下所有以.list结尾的文件 代码:locate /etc/\*.list sudo find /etc/ -name \*.list
- SPRING的事务配置详解
spring事务配置的两种方式: 1.基于XML的事务配置.2.基于注解方式的事务配置. 前言:在我们详细介绍spring的两种声明式事务管理之前,我们需要先理解这些概念 1)spring的事务管理是 ...
- MySQL+Amoeba实现数据库读写分离
参考:https://www.cnblogs.com/liuyisai/p/6009379.html 一,Amoeba是什么 Amoeba(变形虫)项目,专注 分布式数据库 proxy 开发.座落与C ...
- scokte tcp/ip
import scoket# 服务端 server = socket.socket() ip_port = ("127.0.0.1",8001) server.bind(ip_po ...
- 对于adc dac使用细节
1. 要更具内部线路图决定引脚分配,adc和dac绑定在一个线路上,所以设计的时候最好尽量间隔三个引脚以上,如果adc必须放到一起,请使用开关控制,但是dma等可能不能正常工作. 2.dac输出内部缓 ...
- en-zh(科学技术)science and technology
S Korea to roll out 5G韩国正式推5G商用服务 South Korea will become the first country to commercially launch f ...
- C 缓冲区过读 if (index >= 0 && index < len)
C 缓冲区过读 if (index >= 0 && index < len) CWE - CWE-126: Buffer Over-read (3.2) http://cw ...
- Chap1:全景图[Computer Science Illuminated]
参考书目:Dale N . 计算机科学概论(原书第5版)[M]. 机械工业出版社, 2016 from library Chap1:全景图 1.1计算系统 1.2计算的历史 1.3计算工具与计算学科 ...
- python学习目录(转载)
python基础篇 python 基础知识 python 初始python python 字符编码 python 类型及变量 python 字符串详解 python 列表详解 ...