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 ...
随机推荐
- 阿里云服务器 通过JavaMail发送邮箱STMP问题 25端口被禁用 使用SSL协议465端口
1 问题描述 我们传统使用的比较简单的是 STMP 25端口收发邮件 今天发现刚购买的阿里云服务器不能作为客户端通过STMP 25端口发送邮件 开始在网上有说发现是JDK1.8的原因,然后自己也把JD ...
- iTerm2中粘贴tab问题
点过Remember 后,这个窗口就再也不弹出来了.可随后想修改配置,在preferences中又没有找到. 解决方案: 思路:/Users/${name}/Library/Preferences/c ...
- 170823、SQL Update多表联合更新的方法
SQL Update多表联合更新的方法 (1) sqlite 多表更新方法 update t1 set col1=t2.col1 from table1 t1 inner join table2 t2 ...
- 创建数据库,创建数据库表,例子。MySQL语句
1.创建数据库: 创建的代码:create 数据库的代码:database 数据库表名:随便起,只要自己记住就行.test create database test; 2.删除数据库: 删 ...
- vue 打包的项目当背景图路径错误
当背景图路径错误时: 在build/utils.js中添加或更改这句话:publicPath: '../../',
- JavaScript三种弹出框(alert,confirm和prompt)用法举例
http://blog.csdn.net/lucky51222/article/details/45604681 我们在做网页交互的时候往往需要用户在操作之前弹出一个提示消息框来让用户做一些点击才能继 ...
- 524 (Div. 2) Masha and two friends
Codeforces Round #524 (Div. 2) C. Masha and two friends 题目链接 题意:较为简单,初始给定这个白黑相交的格子,第一遍把坐标范围内的全部涂白,第二 ...
- FFmpeg制作+x264+faac
https://blog.csdn.net/leixiaohua1020/article/details/47071547 雷神的博客 https://www.jianshu.com/p/3f023 ...
- Kubernetes中的nodePort,targetPort,port的区别和意义(转)
原文https://blog.csdn.net/u013760355/article/details/70162242 https://blog.csdn.net/xinghun_4/article/ ...
- 2017年蓝桥杯省赛A组c++第5题(递归算法填空)
/* 由 A,B,C 这3个字母就可以组成许多串. 比如:"A","AB","ABC","ABA","AACB ...