Skip to content

Commit adbdd86

Browse files
committed
Calculate delta in beforeMount hook.
1 parent 10f6f0b commit adbdd86

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ Vue.component('virtual-list', {
100100
if (delta.page_type === 'PREV') {
101101
// already the first page
102102
if (delta.start_index === 0) {
103-
list = items.slice(0, this.amount);
103+
list = items.filter((item, index) => {
104+
return index >= 0 && index < this.amount;
105+
});
104106
} else {
105107
list = items.filter((item, index) => {
106108
if (index === delta.start_index - this.amount) {
@@ -157,20 +159,15 @@ Vue.component('virtual-list', {
157159
},
158160

159161
beforeMount () {
160-
this.$options.delta.view_height = this.remain * this.unit;
161-
},
162-
163-
mounted () {
164162
let delta = this.$options.delta;
165163
delta.joints = Math.ceil(this.remain / 2);
164+
delta.view_height = this.remain * this.unit;
166165
delta.bench_padding = delta.joints * this.unit;
167166
},
168167

169-
beforeUpdate () {},
170-
171168
updated () {
172-
let delta = this.$options.delta;
173169
window.requestAnimationFrame(() => {
170+
let delta = this.$options.delta;
174171
this.$refs.container.scrollTop = delta.padding_top + delta.bench_padding;
175172
});
176173
},

0 commit comments

Comments
 (0)