Skip to content

Commit 44361ad

Browse files
authored
Merge pull request #87 from pixlo/pagination_reactive_recalculation
[Pagination] Reactive calculation of sliceStart
2 parents a036abd + 0b0cc77 commit 44361ad

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/components/pagination/Pagination.vue

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,6 @@
6868
sliceStart: 0
6969
}
7070
},
71-
watch: {
72-
value (value) {
73-
if (value > this.sliceStart + this.maxSize) {
74-
if (value > this.totalPage - this.maxSize) {
75-
this.sliceStart = this.totalPage - this.maxSize
76-
} else {
77-
this.sliceStart = value - 1
78-
}
79-
} else if (value < this.sliceStart + 1) {
80-
if (value - this.maxSize > 0) {
81-
this.sliceStart = value - this.maxSize
82-
} else {
83-
this.sliceStart = 0
84-
}
85-
}
86-
}
87-
},
8871
computed: {
8972
pageSize () {
9073
return this.size ? `pagination-${this.size}` : ``
@@ -102,6 +85,22 @@
10285
}
10386
},
10487
methods: {
88+
calculateSliceStart() {
89+
if (this.value > this.sliceStart + this.maxSize) {
90+
if (this.value > this.totalPage - this.maxSize) {
91+
this.sliceStart = this.totalPage - this.maxSize
92+
} else {
93+
this.sliceStart = this.value - 1
94+
}
95+
} else if (this.value < this.sliceStart + 1) {
96+
if (this.value - this.maxSize > 0) {
97+
this.sliceStart = this.value - this.maxSize
98+
} else {
99+
this.sliceStart = 0
100+
}
101+
}
102+
},
103+
105104
onPageChange (page) {
106105
if (page > 0 && page <= this.totalPage) {
107106
this.$emit('input', page)
@@ -118,6 +117,10 @@
118117
this.sliceStart = start
119118
}
120119
}
120+
},
121+
created() {
122+
this.calculateSliceStart()
123+
this.$watch(vm => [vm.value, vm.maxSize, vm.totalPage].join(), this.calculateSliceStart)
121124
}
122125
}
123126
</script>

0 commit comments

Comments
 (0)