创建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. 如何快速将磁盘的MBR分区方式改成GPT分区方式

    注:修改分区格式时此硬盘不能是在使用状态(简单说就是不能出现在盘符中),如果在使用中先在计算机的磁盘管理中删除卷. 由于MBR分区表模式的硬盘最大只支持2T的硬盘空间,而现在我们的硬盘越来越大,有时候 ...

  2. 3 Linux性能优化之 CPU上下文

  3. PatchMatchStereo可能会需要的Rectification

    在稠密三维重建中,rectification可以简化patch match的过程.在双目特征匹配等场景中其实也用得到,看了一下一篇论文叫< A Compact Algorithm for Rec ...

  4. angular get 数据请求

    数据请求 get 新建一个服务 1. ng g service services /+服务名  eg:ng g service services/player 在此服务中进行设置 引入自带组件以及注册 ...

  5. [转帖]java面试和笔试大全

    java面试和笔试大全 https://www.cnblogs.com/linzheng/archive/2011/01/05/1926856.html 2.String是最基本的数据类型吗? 基本数 ...

  6. C语言知识点总结篇

    Debug和Release版本比较 Debug附加了许多调试信息,主要用于调试,故文件大: Release是经过优化后的版本,去掉了调试信息,代码进行了优化,故文件较小,且编译速度快过Debug,用于 ...

  7. Golang读取并修改非主流配置文件

    今天工作中碰到的问题,要求修改此配置文件,没看出来是什么格式,用了下面的思路: mysql { # If any of the files below are set, TLS encryption ...

  8. laravel5.4 中 dd和dump的区别。

    在laravel中dd和dump 都是打印的数据的,但是 dd会终止程序的运行,dump不会. 而且dump打印出来的数据在浏览器上是高亮的哦(很有逼格的~). 上图为dump打印出来的. 上图为dd ...

  9. js获取简单表单对象(1)

    <form id="form">     <input type="text" name="username" value ...

  10. Javascript PC Emulator

    Javascript PC Emulator https://bellard.org/jslinux/ JSLinux Run Linux or other Operating Systems in ...