This repository was archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathpagination.js
More file actions
68 lines (64 loc) · 1.33 KB
/
pagination.js
File metadata and controls
68 lines (64 loc) · 1.33 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
Vue.component('pagination', {
template: '#pagination-template',
props: {
current: {
type: Number,
default: 1
},
total: {
type: Number,
default: 0
},
perPage: {
type: Number,
default: 9
},
pageRange: {
type: Number,
default: 2
}
},
computed: {
pages: function() {
var pages = []
for(var i = this.rangeStart; i <= this.rangeEnd; i++) {
pages.push(i)
}
return pages
},
rangeStart: function() {
var start = this.current - this.pageRange
return (start > 0) ? start : 1
},
rangeEnd: function() {
var end = this.current + this.pageRange
return (end < this.totalPages) ? end : this.totalPages
},
totalPages: function() {
return Math.ceil(this.total/this.perPage)
},
nextPage: function() {
return this.current + 1
},
prevPage: function() {
return this.current - 1
}
},
methods: {
hasFirst: function() {
return this.rangeStart !== 1
},
hasLast: function() {
return this.rangeEnd < this.totalPages
},
hasPrev: function() {
return this.current > 1
},
hasNext: function() {
return this.current < this.totalPages
},
changePage: function(page) {
this.$emit('page-changed', page)
}
}
})