-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvue-pagination.js
110 lines (100 loc) · 3.5 KB
/
vue-pagination.js
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
module.exports = {
template: '<nav class=" {{navClass}} " v-show="visible">' +
'<ul class="pagination {{size}} " >' +
'<li v-if="pagination.current_page > 1">' +
'<a href="#" aria-label="Previous" @click.prevent="changePage(1)">' +
'<span aria-hidden="true">First</span>' +
'</a>' +
'</li>' +
'<li v-if="pagination.current_page > 1">' +
'<a href="#" aria-label="Previous" @click.prevent="changePage(pagination.current_page - 1)">' +
'<span aria-hidden="true">«</span>' +
'</a>' +
'</li>' +
'<li v-if="pagination.current_page > 1">' +
'<a href="#" aria-label="Next" @click.prevent="changePage(from)">' +
'<span aria-hidden="true">...</span>' +
'</a>' +
'</li>' +
'<li v-for="num in data" :class="{\'active\': num == pagination.current_page}">' +
'<a href="#" @click.prevent="changePage(num)">{{ num }}</a>' +
'</li>' +
'<li v-if="pagination.current_page < pagination.total_pages">' +
'<a href="#" aria-label="Next" @click.prevent="changePage(to)">' +
'<span aria-hidden="true">...</span>' +
'</a>' +
'</li>' +
'<li v-if="pagination.current_page < pagination.total_pages">' +
'<a href="#" aria-label="Next" @click.prevent="changePage(pagination.current_page + 1)">' +
'<span aria-hidden="true">»</span>' +
'</a>' +
'</li>' +
'<li v-if="pagination.current_page < pagination.total_pages">' +
'<a href="#" aria-label="Next" @click.prevent="changePage(pagination.total_pages)">' +
'<span aria-hidden="true">Last</span>' +
'</a>' +
'</li>' +
'</ul>' +
'</nav>',
props: {
pagination: {
type: Object,
required: true
},
callback: {
type: Function,
required: true
},
size: {
type: String,
default: ""
},
navClass: {
type: String,
default: ""
},
offset: {
type: Number,
default: 4
},
visible: {
type: Number,
default: 1
}
},
computed: {
data: function () {
this.visible = 1;
var from = this.pagination.current_page - this.offset;
if(from < 1) {
from = 1;
}
var to = from + (this.offset * 2);
if(to >= this.pagination.total_pages) {
to = this.pagination.total_pages;
}
this.from = from;
this.to = to;
var arr = [];
while (from <=to) {
arr.push(from);
from++;
}
console.log(arr);
if(arr.length == 1)
this.visible = 0
return arr;
}
},
watch: {
'pagination.per_page': function () {
this.callback();
}
},
methods: {
changePage: function (page) {
this.$set('pagination.current_page', page);
this.callback();
}
}
};