创建pagination.vue

/*
* 所需参数
* total Number 总页数
* current Number 当前页面下标
* pageSize Number 页面显示条数
* sizes Array 页面条数容器数组
* jump(index) function 重新获取数据的方法
* getPageSize(index) function 更改页面显示条数的方法
*/
<style lang="less">
@color:#1199F0;
.page-wrapper{
padding:20px 10px;
ul{
overflow: hidden;
display: table;
margin: auto;
height: 50px;
list-style: none;
li{
float:left;
}
}
.paging-size{
height:30px;
margin-right:20px;
select{
width:50px;
height:30px;
text-align:center;
border:1px solid @color;
}
}
.paging-item{
height: 30px;
line-height: 30px;
margin: 3px;
padding-left:12px;
padding-right:12px;
border-radius: 5px;
font-size: 12px;
color: #;
cursor: pointer;
&:hover,&.current{
color:#fff;
background-color: @color;
}
}
.paging-jump{
margin-left:20px;
margin-top:3px;
height:30px;
font-size:;
overflow: hidden;
input[type="number"]{
float: left;
padding: 5px;
width:50px;
height:28px;
text-align:center;
border:1px solid @color;
}
input[type="button"]{
float: left;
padding: 12px;
height:30px;
border:none;
color:#fff;
background-color: @color;
}
}
}
</style>
<template>
<div class="page-wrapper">
<ul>
<li class="paging-size">
<select @change="getPageSize">
<option v-for="i in sizes" :value="i" :selected="i==pageSize">{{i}}</option>
</select>
</li>
<li class="paging-item" v-if="current!=1" @click='jump(1)'>首页</li>
<li class="paging-item" v-if="current-1>0" @click='jump(current-1)'>上一页</li>
<li class="paging-item" v-if="current-2>0" @click='jump(current-2)'>{{current-}}</li>
<li class="paging-item" v-if="current-1>0" @click='jump(current-1)'>{{current-}}</li>
<li class="paging-item current" @click='jump(current)'>{{current}}</li>
<li class="paging-item" v-if="total-current>1" @click='jump(current+1)'>{{current+}}</li>
<li class="paging-item" v-if="total-current>2" @click='jump(current+2)'>{{current+}}</li>
<li class="paging-item" v-if="total-current>1" @click='jump(current+1)'>下一页</li>
<li class="paging-item" v-if="current!=total" @click='jump(total)'>尾页</li>
<li class="paging-jump">
<input type="number" v-model="jumpPage" :max="total" min=""/>
<input type="button" value="跳转" @click='jump(jumpPage)'/>
</li>
</ul>
</div>
</template>
<script>
export default {
data(){
return {
jumpPage:
}
},
props:{
total:Number,
current:Number,
pageSize:Number,
sizes:{
type:Array,
default:function(){
return [,,]
}
}
},
mounted(){
if(this.total-this.current>){
this.jumpPage=this.current+;
}
else{
this.jumpPage=;
}
},
watch:{
current(){
if(this.total-this.current>){
this.jumpPage=this.current+;
}
else{
this.jumpPage=;
}
}
},
methods:{
jump(index){
index=Number(index);
if (this.current != index && index > && index < this.total + ) {
this.$emit('jump', index);
}
},
getPageSize(e){
let pageSize=Number(e.target.value);
this.$emit('getPageSize',pageSize);
}
}
}
</script>

index.vue中注册

  components:{
'v-pagination':(resolve)=>{
require(['components/pagination'],resolve);
}
}

index.vue中使用

      <v-pagination
:total="total"
:current="current"
:pageSize="pageSize"
@getPageSize="getPageSize"
@jump="jump"
></v-pagination>

完整index.vue代码

<template>
<div class="wrapper" v-swipeleft='left' v-swiperight='right'>
<v-pagination
:total="total"
:current="current"
:pageSize="pageSize"
@getPageSize="getPageSize"
@jump="jump"
></v-pagination>
</div>
</template> <script>
export default {
data () {
return {
total:,
current:,
pageSize:
}
},
methods:{
jump(index){
this.current=index;
},
getPageSize(pageSize){
this.pageSize=pageSize;
}
},
components:{
'v-pagination':(resolve)=>{
require(['components/pagination'],resolve);
}
}
}
</script>
<style lang="less" scoped="scoped">
.wrapper{
height:%;
width:%;
}
</style>

vue实现分页组件的更多相关文章

  1. 基于Vue封装分页组件

    使用Vue做双向绑定的时候,可能经常会用到分页功能 接下来我们来封装一个分页组件 先定义样式文件 pagination.css ul, li { margin: 0px; padding: 0px;} ...

  2. 基于iview 封装一个vue 表格分页组件

    iview 是一个支持中大型项目的后台管理系统ui组件库,相对于一个后台管理系统的表格来说分页十分常见的 iview是一个基于vue的ui组件库,其中的iview-admin是一个已经为我们搭好的后天 ...

  3. vue 封装分页组件

    分页 一般都是调接口, 接口为这种格式 {code: 0, msg: "success",…} code:0 data:{ content:[{content: "11& ...

  4. semantic、vue 使用分页组件和日历插件

    最近正在试试semantic-ui,结合了vue,这里忍不住吐槽semantic和vue的友好度简直不忍直视,不过既然用了,这里就分享几个用到的插件了 1.分页组件(基于vue) var pageCo ...

  5. vue 自定义分页组件

    vue2.5自定义分页组件,可设置每页显示条数,带跳转框直接跳转到相应页面 Pagination.vue 效果如下图: all: small(只显示数字和上一页和下一页): html <temp ...

  6. vue自定义分页组件---切图网

    vue2.5自定义分页组件 Pagination.vue,可设置每页显示条数,带跳转框直接跳转到相应页面,亲测有用.目前很多框架自带有分页组件比如elementUI,不过在面对一个拿到PSD稿,然后重 ...

  7. vue封装分页组件

    element提供的分页是已经封装好的组件,在这里再次封装是为了避免每个用到分页的页面点击跳转时都要写一遍跳转请求 分页组件 <!--分页组件--> <template> &l ...

  8. vue element-ui 分页组件封装

    <template> <el-pagination @size-change="handleSizeChange" @current-change="h ...

  9. vue的分页组件

    <template> <div class="page-nav"> <div class="page-btn-wrap"> ...

随机推荐

  1. ASP.Net Core使用分布式缓存Redis从入门到实战演练

    一.课程介绍 人生苦短,我用.NET Core!缓存在很多情况下需要用到,合理利用缓存可以一方面可以提高程序的响应速度,同时可以减少对特定资源访问的压力.  所以经常要用到且不会频繁改变且被用户共享的 ...

  2. Python【每日一问】31

    问: [基础题]:有 n 个人围成一圈,顺序排号.从第一个人开始报数(从 1 到 3 报数) ,凡报到 3 的人退出圈子,问最后留下的是原来第几号的那位. (n由键盘输入,比如n=100) [提高题] ...

  3. 鼠标滚轮滚动慢/拖动Office出现滞后问题处理

    一.说明 我对外设一直不是很了解,买的鼠标今天到了,使用时遇到了两个问题在这里记一下. 二.滚轮滚动慢处理 问题描述:在网页中滚动滚轮每次只能上下移动一点点,感觉很难受. 问题原因:此问题是滚轮滚动一 ...

  4. 用Powershell强制同步Windows主机与Internet time server的时间

    第一步,判断Windows Time服务是否正在运行,如果没有,则开启它. 第二步,强制同步,不知为何,往往第一次会失败,那么就多运行几次好了. Get-Service w32time | Where ...

  5. idea 全局内容搜索和替换

    在做项目时,有时会在整个项目里或指定文件夹下进行全局搜索和替换,这是一个很方便功能.使用方法如下: 一.全局搜索1.使用快捷键Ctrl+Shift+F打开搜索窗口,或者通过点击Edit–>Fin ...

  6. GoCN每日新闻(2019-09-23)

    1. 查看 Go 的代码优化过程http://xargin.com/go-compiler-opt 2. go 学习笔记之仅仅需要一个示例就能讲清楚什么闭包 https://segmentfault. ...

  7. CentOS 7 -防火墙设置--安装数据库,远程连接报错--Can't connect to MySQL server on localhost (10061)

    前提简介:在CentOS 7 上安装了mysql5.7版本,已设置了远程访问权限,但是其他服务器无法访问到此Mysql,提示[Can't connect to MySQL server on loca ...

  8. Java学习:内部类的概念于分类

    内部类的概念于分类 如果一个事物的内部类包含另一个事物,那么这就是一个类内部包含另一个类.例如:身体和心脏的关系,又如:汽车和发动机的关系. 分类 成员内部类 局部内部类(包含匿名内部类) 成员内部类 ...

  9. 使用HttpWebRequest和HttpWebResponse时接收数据中文乱码的情况

    今天在调试一个get请求的接口的时候发现HttpWebResponse方法接收数据的时候,中文出现乱码的情况. 原因是格式编码转码的问题. 原来自从Windows 2000之后的操作系统在文件处理时默 ...

  10. C# VB .net读取识别条形码线性条码codabar

    codabar是比较常见的条形码编码规则类型的一种.如何在C#,vb等.NET平台语言里实现快速准确读取codabar条形码呢?答案是使用SharpBarcode! SharpBarcode是C#快速 ...