-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPaging.vue
83 lines (68 loc) · 2.04 KB
/
Paging.vue
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
<template>
<ul class="pagination">
<li v-if="active > 3">
<a href="#" @click.stop.prevent="update(0)">{{ 1 }}</a>
</li>
<li v-if="active > 3" class="disabled">
<a href="#">...</a>
</li>
<li v-for="n in numbers" :class="{'active' : n == active}">
<a href="#" @click.stop.prevent="update(n)">{{ n+1 }}</a>
</li>
<li v-if="active < length-4" class="disabled">
<a href="#">...</a>
</li>
<li v-if="active < length-4">
<a href="#" @click.stop.prevent="update(length-1)">{{ length }}</a>
</li>
</ul>
</template>
<script>
export default{
data() {
return {
n: 0,
active: 0
}
},
props:['items', 'count', 'type'],
computed: {
length: function() {
return Math.ceil(this.items.length / this.count);
},
min: function() {
if(this.active < 4) {
return 0;
} else if ( this.active > this.length - 4) {
return this.length-5;
} else {
return this.active-2;
}
},
max: function() {
if (this.length < 6) {
return this.length;
} else if(this.active < 4) {
return 6;
} else if ( this.active > this.length - 5) {
return this.length;
} else {
return this.active+3;
}
},
numbers: function() {
var temp = [];
for(var i = this.min; i < this.max; i++) {
temp.push(i);
}
return temp
}
},
methods: {
update: function(n){
this.active = n;
this.$dispatch('page-' + this.type, this.active);
}
}
}
</script>