基于 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的分页封装,可是都不是我想要的结果,那么今天我 ...
随机推荐
- xocodebulid 自动化打包 解决提示 ld: library not found for -lPods 问题
如果你的项目用到cocopod 第三方库.使用xcodebulid 估计会出现 ld: library not found for -lPods 以下 是我的解决办法 xcodebuild -work ...
- 冰淇淋三明治 (Android 4.0)介绍
原文:http://android.eoe.cn/topic/summary 冰淇淋三明治 (Android 4.0) 是 Android 在设计上的一个里程碑.它将 Honeycomb 提供给平板的 ...
- nginx 屏蔽恶意请求
https://www.xlongwei.com/detail/nginx-%E5%B1%8F%E8%94%BD%E6%81%B6%E6%84%8F%E8%AF%B7%E6%B1%82 nginx可以 ...
- .NET CORE EF 框架调用存储过程
; //多个参数多表组合值 SqlParameter[] Param = { new SqlParameter("@UserId", System.Data.SqlDbType.V ...
- [mBean]-Delphi框架,回归简单,自然。
[mBean]的萌芽 最近公司要求把我们公司的任务可以外包,问我有没有好的方案. 如果要其他程序员的人来做我们内部的框架会导致了,内部的框架需要公布很多单元和逻辑,思路.其次要把我们的思路和规则强加给 ...
- vue项目的搭建
ps: 想了解更多vue相关知识请点击VUE学习目录汇总 Vue作为前端三大框架之一截至到目前在github上以收获44,873颗星,足以说明其以悄然成为主流.16年10月Vue发布了2.x版本,经过 ...
- img的src不连接本地地址实现输出一个图片(使用base64)
<img alt="100%x180" data-src="holder.js/100%x180" style="height: 180px; ...
- LeetCode: Add Two Numbers 解题报告
Add Two NumbersYou are given two linked lists representing two non-negative numbers. The digits are ...
- 确保安全的HTTPS(使用混合加密的HTTPS,前端面试常问)第二篇
苹果已经确定,在iOS9中通信机制采用HTTPS了. 第一篇:http://www.cnblogs.com/ziyi--caolu/p/4742577.html 上一篇详细介绍了为什么要对HTTP进行 ...
- Android开发(三)——Android布局中实现圆角边框
设置corners_bg.xml(设置边框圆角可以在drawable-mdpi目录里定义一个xml): <?xml version="1.0" encoding=" ...