基于 bootstrap 的 vue 分页组件
基于 bootstrap 的 vue 分页组件,我想会有那么一部分同学,在使用Vue的时候不使用单文件组件,因为不架设 NodeJS 服务端。那么网上流传的 *.vue 的各种分页组件可能无法使用的,我这里提供一个 *.js 的分页组件,下午刚写的,希望对大家有所帮忙,欢迎下载。
下面是如何使用的示例代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<meta charset="utf-8" />
<title>基于 bootstrap 的 vue 分页组件 - 演示</title>
<link href="Content/bootstrap.css" rel="stylesheet" />
</head>
<body>
<div id="app" class="container">
<br />
<h4>基于 bootstrap 的 vue 分页组件 - 演示</h4>
<!-- 注:showListBar、showIndexBar 两个属性是可选项,注:="true" 其实是可以省略的 -->
<!-- 注:pageSize,barSize,pageSizeList 三个属性是可选项 -->
<pager show-list-bar :show-index-bar="true"
:page-size="30" :bar-size="10" :page-size-list="[1, 15, 25, 30]"
:total="1024" v-model="xxx" @change="pagechange();"></pager>
<!-- 注:total、v-model、change基本上来说,算是必选项了 -->
<hr />
当前页: {{ xxx }}
</div>
<script src="Scripts/vue-2.5.2.min.js"></script>
<script src="Scripts/vue-pager-1.0.js"></script>
<script>
new Vue({
el: "#app",
data: function () {
return {
xxx: 1,
}
},
methods: {
//翻页事件
pagechange: function () {
console.log("翻页了:", this.xxx);
},
}
});
</script>
</body>
</html>
组件的代码如下:
// 基于 bootstrap 的分页组件 by 周游
// vue-pager-1.0.js
Vue.component('pager', {
model: {
prop: 'pageIndex',
event: 'change'
},
props: {
"total": { required: true, type: Number }, //总记录数
"pageSize": Number, //页大小
"barSize": { type: Number, default:10 }, //页码器上,一次显示几页
"pageIndex": { required: true, type: Number}, //当前页 (v-model)
"pageSizeList": { type: Array, default: [10, 20, 30, 50, 100] }, //每页显示多少条的数组
"showListBar": { type: Boolean, default: false }, //显示“每页 X 条”栏
"showIndexBar": { type: Boolean, default: true }, //显示“第几页/共几页”栏
},
data: function () {
return {
pindex: 1, //当前页
psize: 10, //页大小
}
},
computed: {
//总页数 (计算值)
pcount: function () {
return parseInt((this.total - 1) / this.psize) + 1;
},
//页码集
indexes: function () {
//参数修正
this.pindex = this.pageIndex || 1;
if (isNaN(this.pindex)) this.pindex = 1;
if (this.pindex < 1) this.pindex = 1;
if (this.pindex > this.pcount) this.pindex = this.pcount;
//求indexes
var left = 1;
var right = this.pcount;
var bcenter = parseInt(this.barSize / 2);
var ar = [];
if (this.pcount > this.barSize) {
if (this.pindex > bcenter && this.pindex <= this.pcount - bcenter) {
left = this.pindex - bcenter
right = this.pindex + (bcenter - 1)
+ (this.barSize % 2); //奇数多显示一页
//console.log("中间的页", this.pindex);
} else {
if (this.pindex <= bcenter) {
left = 1
right = this.barSize;
//console.log("当前页是开始几页", this.pindex);
} else {
right = this.pcount;
left = this.pcount - (this.barSize - 1);
//console.log("当前页是最后几页", this.pindex);
}
}
}
while (left <= right) {
ar.push(left)
left++
}
return ar;
},
showLast: function () {
return this.pindex != this.pcount
},
showFirst: function () {
return this.pindex != 1
}
},
watch: {
//监视如果 pindex 发生变化,就触发 change 事件
pindex: function () {
this.pageIndex = this.pindex;
this.$emit('change', this.pageIndex);
},
},
methods: {
//跳转页码
go: function (i) {
if (i < 1 || i > this.pcount) return;
this.pindex = i;
}
},
template: '<ul class="pagination">\
<li :class="{disabled:!showFirst}"><a href="javascript:void(0)" @click="go(1)">第一页</a></li>\
<li :class="{disabled:!showFirst}"><a href="javascript:void(0)" @click="go(pindex-1)">上一页</a></li>\
<li v-for="i in indexes" :class="{active:i==pindex}"><a href="javascript:void(0)" @click="go(i)">{{ i }}</a></li>\
<li :class="{disabled:!showLast}"><a href="javascript:void(0)" @click="go(pindex+1)">下一页</a></li>\
<li :class="{disabled:!showLast}"><a href="javascript:void(0)" @click="go(pcount)">第末页</a></li>\
<li v-if="showListBar" class="form-inline"><span>每页 \
<select class="form-control" v-model.number="psize" \
style="padding:0 0px;height:18px;width:48px;text-align:center;margin-top:-4px;" >\
<option v-for="ps in pageSizeList">{{ ps }}</option>\
</select> 条</span></li>\
<li v-if="showIndexBar" class="form-inline"><span>第 <input v-model.number="pindex" type="text" class="form-control" style="padding:0;height:18px;width:42px;text-align:center;margin-top:-4px;" /> 页 / 共{{pcount}}页</span></li>\
</ul>',
created: function () {
this.psize = this.pageSize || this.psize;
//一进来就触发 change 事件
this.$emit('change', this.pageIndex);
}
});
基于 bootstrap 的 vue 分页组件的更多相关文章
- 基于vue2.0的分页组件开发
今天安排的任务是写基于vue2.0的分页组件,好吧,我一开始是觉得超级简单的,但是越写越写不出来,写的最后乱七八糟的都不知道下句该写什么了,所以重新捋了思路,小结一下- 首先写组件需要考虑: 要从父组 ...
- 循序渐进BootstrapVue,开发公司门户网站(1)---基于Bootstrap网站模板构建组件界面
在前面随笔<使用BootstrapVue相关组件,构建Vue项目界面>概括性的介绍了BootstrapVue的使用过程,其实选用这个主要就是希望能够用来构建一些公司门户网站的内容,毕竟基于 ...
- 基于jQuery封装的分页组件
前言: 由于项目需要实现分页效果,上jQuery插件库找了下,但是木有找到自己想要的效果,于是自己封装了个分页组件. 思路: 主要是初始化时基于原型建立的分页模板然后绑定动态事件并实现刷新DOM的分页 ...
- 一款基于Bootstrap的js分页插件bootstrap-paginator使用实例
Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富.它提供了一系列的参数用来支持用户的定制,提供了公共的方法可随时获得插件状态的改变,以及事件来监听用户的动作 ...
- java+springBoot+Thymeleaf+vue分页组件的定义
导读 本篇着重介绍java开发环境下,如何写一个vue分页组件,使用到的技术点有java.springBoot.Thymeleaf等: 分页效果图 名称为vuepagerbasic的分页组件,只包含上 ...
- 基于 Python 的自定义分页组件
基于 Python 的自定义分页组件 分页是网页中经常用到的地方,所以将分页功能分出来,作为一个组件可以方便地使用. 分页实际上就是不同的 url ,通过这些 url 获取不同的数据. 业务逻辑简介 ...
- vue分页组件table-pagebar
之前一直接触都是原始的前端模型,jquery+bootstrap,冗杂的dom操作,繁琐的更新绑定.接触vue后,对前端MVVM框架有了全新的认识.本文是基于webpack+vue构建,由于之前的工作 ...
- 基于avalon1.4.x ----分页组件编写
avalon分页组件 (1.4.x版本) 随着avalon2的推出,avalon1的官网已经不再维护了,现在似乎是找不到avalon 1.4版本的官方文档了,所以本文章所有的内容均不保证正确性,只能保 ...
- 基于jQuery封装的分页组件(可自定义设置)
jQuery封装的分页组件 前几天做了一个vue的组件分页,而现在需求是jquery的分页,我就根据我自己的需求写了一个.在网上找了很久的基于jquery的分页封装,可是都不是我想要的结果,那么今天我 ...
随机推荐
- linux分享一:网络设置
在Linux中,TCP/IP网络的配置信息存在几个不同的文件里面,这些文件分别就是 /etc/sysconfig/network. 网卡配置文件. /etc/hostc. /ect/resolv.co ...
- Atitit undac网络设备管理法案 (路由器 交换机等) 法案编号USRr101510
Atitit undac网络设备管理法案 (路由器 交换机等) 法案编号USRr101510 1.1. 版本历史1 1.2. 密码设置规范 与原则1 1.3. 如何设置密码 ,设置一个简单又安 ...
- tengine 的优化
查服务器CPU的核数 : [root@c01 conf]# grep processor /proc/cpuinfo |wc -l 4 [root@c01 conf]# grep -c process ...
- Natural Language Processing 课程,文章,论文
CS224n: Natural Language Processing with Deep Learning http://cs224d.stanford.edu/syllabus.html http ...
- Backpropagation In Convolutional Neural Networks
http://www.jefkine.com/general/2016/09/05/backpropagation-in-convolutional-neural-networks/ http://w ...
- TCPConnectionTermination
http://www.serverframework.com/asynchronousevents/2011/01/time-wait-and-its-design-implications-for- ...
- C#对Sql Server TEXT字段存储的实现(使用存储过程)
1.这里先准备数据库:在数据库中建立一个News数据表,字段为id,title,content2.建立用于插入news的存储过程:NewsInsert和NewsUpdate,代码如下: ),@cont ...
- (原创)C++11改进我们的程序之右值引用
本次主要讲c++11中的右值引用,后面还会讲到右值引用如何结合std::move优化我们的程序. c++11增加了一个新的类型,称作右值引用(R-value reference),标记为T & ...
- C++类成员函数
c++的两大特色是多态和模板.其中多态是通过继承和虚函数来实现的,其中虚函数是通过每个对象里面的虚表来实现的.如果这个对象的类有虚函数,那么这个类就有一张虚表,存的是每个虚函数的入口地址,而这个类的每 ...
- Asp.Net MVC App_Code无法识别
Asp.Net MVC需要写公共类的时候 右击添加 App_Code 文件夹,新建类—>右击类—>属性,生成操作 —>选择 —>编译 Asp.Net MVC项目本身是个应用程序 ...