vue实现分页组件
创建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实现分页组件的更多相关文章
- 基于Vue封装分页组件
使用Vue做双向绑定的时候,可能经常会用到分页功能 接下来我们来封装一个分页组件 先定义样式文件 pagination.css ul, li { margin: 0px; padding: 0px;} ...
- 基于iview 封装一个vue 表格分页组件
iview 是一个支持中大型项目的后台管理系统ui组件库,相对于一个后台管理系统的表格来说分页十分常见的 iview是一个基于vue的ui组件库,其中的iview-admin是一个已经为我们搭好的后天 ...
- vue 封装分页组件
分页 一般都是调接口, 接口为这种格式 {code: 0, msg: "success",…} code:0 data:{ content:[{content: "11& ...
- semantic、vue 使用分页组件和日历插件
最近正在试试semantic-ui,结合了vue,这里忍不住吐槽semantic和vue的友好度简直不忍直视,不过既然用了,这里就分享几个用到的插件了 1.分页组件(基于vue) var pageCo ...
- vue 自定义分页组件
vue2.5自定义分页组件,可设置每页显示条数,带跳转框直接跳转到相应页面 Pagination.vue 效果如下图: all: small(只显示数字和上一页和下一页): html <temp ...
- vue自定义分页组件---切图网
vue2.5自定义分页组件 Pagination.vue,可设置每页显示条数,带跳转框直接跳转到相应页面,亲测有用.目前很多框架自带有分页组件比如elementUI,不过在面对一个拿到PSD稿,然后重 ...
- vue封装分页组件
element提供的分页是已经封装好的组件,在这里再次封装是为了避免每个用到分页的页面点击跳转时都要写一遍跳转请求 分页组件 <!--分页组件--> <template> &l ...
- vue element-ui 分页组件封装
<template> <el-pagination @size-change="handleSizeChange" @current-change="h ...
- vue的分页组件
<template> <div class="page-nav"> <div class="page-btn-wrap"> ...
随机推荐
- SpringMvc通过controller上传文件代码示例
上传文件这个功能用的比较多,不难,但是每次写都很别扭.记录在此,以备以后copy用. package com.**.**.**.web.api; import io.swagger.annotatio ...
- Maven 教程(10)— Maven依赖详解
原文地址:https://blog.csdn.net/liupeifeng3514/article/details/79545022 1.何为依赖? 比如你是个男的,你要生孩子,呸呸呸…男的怎么生孩子 ...
- 决策树(下)-Xgboost
参考资料(要是对于本文的理解不够透彻,必须将以下博客认知阅读,方可更加了解Xgboost): 1.对xgboost的理解(参考资料1和4是我认为对Xgboost理解总结最透彻的两篇文章,其根据作者pa ...
- arguments 使用
function test(){ var paramsNum = arguments.length; var sum = 0; for(var i = 0;i<paramsNum;i++){ c ...
- JS获取当前时间戳及时间戳的转换
获取现在的Unix时间戳(Unix timestamp) Math.round(new Date().getTime()/1000) //getTime()返回数值的单位是毫秒 Unix时间戳(Un ...
- Java IO---缓冲流和转换流
一. 缓冲流 缓冲流是处理流的一种,也叫高效流,是对4个基本输入输出流的增强,它让输入输出流具有1个缓冲区,能显著减小与外部的IO次数,从而提高读写的效率,并且提供了一些额外的读写方法. 因为 ...
- Python删除列表元素的3种方法
之前看教程的时候比较着急,对这些基础掌握不好,过来回顾一下 使用del语句删除 lis = [1, 2, 3, 'a', 'b'] print(lis) del lis[0] print(lis) 输 ...
- zynq开发板外设配置演示
有幸得到米尔电子zynq系列开发板Z-turn Board试用体验,下面说说我这款zynq系列的Z-TURN板子外设配置.从Z-turn Board原理图上看,目前可以配置的FPGA管脚大概有100多 ...
- 【转载】C#通过IndexOf方法获取某一列在DataTable中的索引位置
在C#中的Datatable数据变量的操作过程中,有时候需要知道某一个列名在DataTable中的索引位置信息,此时可以通过DataTable变量的Columns属性来获取到所有的列信息,然后通过Co ...
- npm安装时-S -D作用及区别
-S 即--save(保存) 包名会被注册在package.json的dependencies里面,在生产环境下这个包的依赖依然存在 -D 即--dev(生产) 包名会被注册在package.json ...