基于 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的分页封装,可是都不是我想要的结果,那么今天我 ...
随机推荐
- haproxy 日志配置
haproxy日志配置 haproxy在默认情况不会记录日志,除了在haproxy.conf中的global段指定日志的输出外,还需要配置系统日志的配置文件.下面以centos6.4为例,haprox ...
- 在 Windows Server 2008 中部署带 SignalR 的网站出错
一直是在 Windows Server 2008 R2 或更高版本的 Windows 中进行部署,没有遇到过此现象,不知道是不是因为系统的原因. 现象为从浏览器访问配置 signalr 的地址返回 4 ...
- [LeetCode] Basic Calculator & Basic Calculator II
Basic Calculator Implement a basic calculator to evaluate a simple expression string. The expression ...
- Android Studio 解决 Gradle 依赖冲突的问题
Android Studio 解决 Gradle 依赖冲突的问题 参考链接: Android Studio(Gradle)解决库依赖冲突问题:http://www.mobibrw.com/2016/3 ...
- spring(三) spring事务操作
前面一篇博文讲解了什么是AOP.学会了写AOP的实现,但是并没有实际运用起来,这一篇博文就算是对AOP技术应用的进阶把,重点是事务的处理. --wh 一.jdbcTemplate 什么是JdbcTem ...
- ios7新特性--1
1.用户界面的扁平化 2.UIKit 动态行为支持 应用程序可以设置UIView 对象和其他对象(遵从UIDynamicItem 协议)的动态行为属性.遵从UIDynamicItem协议的对象被称为d ...
- 将redis作为windows服务安装
1,下载redis并解压到一个目录下,然后切换到该目录下,也就是redis-server.exe文件所在的目录 2,在cmd下执行 redis-server --service-install red ...
- CCObject
/**************************************************************************** Copyright (c) 2010 coc ...
- Android 编程下 TextView 添加链接的一种方式
通过如下这种方式给 TextView 添加的链接支持链接样式.点击事件.href 样式,代码如下: package cn.sunzn.tlink; import android.app.Activit ...
- android 调用系统相机拍照 获取原图
好吧,为了这个问题又折腾了一整天.之前在网上找来的方法,如果在onActivityResult中直接用data.getData()的方式来生成bitmap,其实获取的是拍照生成的缩略图!看看尺寸就 ...