pagination.vue
3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<template>
<div class="pagination m-20-0">
<div v-if='pageFalg' class="mb-20">
<em class="page">共【{{ totalPages }}】页</em>
<em class="page ml-5">跳转到<input type="text" class="t-center" style='width:40px;margin:0px 5px;height:30px;' v-model='pageS' @keyup.enter='goPage(pageS*1)'>页</em>
<em class="page text-color-blue ml-10" style='cursor:pointer;' @click='goPage(pageS*1)' >Go>></em>
</div>
<ul>
<li>
<a v-if="pageNo !=1" href="javascript:;"
@click="goPage(1)" class="page">首页</a>
<span v-else class="page">首页</span>
</li>
<li>
<a v-if="pageNo > 1" href="javascript:;" @click="goPage(pageNo - 1)" class="page">上一页</a>
<span v-else class="page">上一页</span>
</li>
<li v-for="index in totalPages" v-show="totalPages<11">
<a v-bind:class="{ 'active': pageNo == index*1 + 1 }" href="javascript:;" v-if="pageNo != index*1 + 1" @click="goPage(index*1 + 1)">{{index + 1}}</a>
<span v-bind:class="{ 'active': pageNo == index*1 + 1 }" v-else>{{index*1 + 1}}</span>
</li>
<li v-for="index in prevnum" v-show="totalPages>10">
<a v-bind:class="{ 'active': pageNo == index }"
href="javascript:;" v-if="pageNo != index "
@click="goPage(index )">{{index }}</a>
<span v-bind:class="{ 'active': pageNo == index }" v-else>{{index }}</span>
</li>
<li v-for="index in nextnum" v-show="totalPages>10" >
<a v-bind:class="{ 'active': pageNo == index }"
href="javascript:;" v-if="pageNo != index "
@click="goPage(index )">{{index }}</a>
<span v-bind:class="{ 'active': pageNo == index }" v-else>{{index }}</span>
</li>
<li>
<a v-if="pageNo < totalPages" @click="goPage(pageNo*1 + 1)" href="javascript:;" class="page">下一页</a>
<span v-else class="page"> 下一页</span>
</li>
<li>
<a v-if="totalPages>1 && pageNo!=totalPages" href="javascript:;"
@click="goPage(totalPages)" class="page">尾页</a>
<span v-else class="page">尾页</span>
</li>
</ul>
</div>
</template>
<script>
module.exports = {
props: {
'pageFalg': {
twoWay: true,
type: String| Boolean ,
default: false
},
'pageNo': {
twoWay: true,
type: String| Number ,
default: 1
},
'totalPages': {
twoWay: true,
type: String | Number,
default: 0
},
pageS:{
twoWay: true,
type: Number,
default: ''
}
// 类型错误报错 张欣欣change
// 'class': {
// type: Array,
// default: []
// }
},
computed:{
prevnum:function(){
var arr=[];
var n=this.pageNo-1;
if(n<=0){
return arr
}
while(n>0){
if(arr.length<3){
arr.unshift(n);
}
n-=1;
}
return arr;
},nextnum:function(){
var arr=[];
var n=this.pageNo;
for(var i=0;i<4;i++){
if(n<this.totalPages){
arr.push(n*1)
n+=1;
}
}
return arr;
}
},
methods: {
goPage: function (num) {
console.log(num)
if(num>this.totalPages){
layer.msg('输入的页码不可大于总页码数!')
return;
}else if(num==''){
layer.msg('页码不可为空!')
return;
}else if(num<=0){
layer.msg('页码不可小于等于0!')
return;
}
this.pageNo = num;
this.pageS='';
this.$dispatch('page-change');
}
}
};
</script>