Skip to content

Commit 4a840de

Browse files
committed
Pick saveDirect from component instance.
1 parent e3dbaf4 commit 4a840de

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

demo/item.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
}
3838
.indx {
3939
width: 50px;
40+
font-weight: bold;
4041
}
4142
.urid {
4243
width: 60px;

demo/request_mock.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Mock from 'mockjs';
22

3-
let user_count = 0;
3+
let user_count = 1;
4+
let request_times = 0;
45
export function fetchData (count) {
56
var list = [];
67
let Random = Mock.Random;
@@ -18,5 +19,7 @@ export function fetchData (count) {
1819
});
1920
}
2021

22+
request_times++;
23+
2124
return list;
2225
}

src/index.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue';
22
import { throttle } from './util';
33

4+
// some data help to calculate
45
let delta = {
56
total: 0,
67
direct: '',
@@ -12,6 +13,16 @@ let delta = {
1213
bench_padding: 0
1314
};
1415

16+
// save scroll direct and last scroll position
17+
const saveDirect = (scrollTop) => {
18+
if (!delta.last_top) {
19+
delta.last_top = scrollTop;
20+
} else {
21+
delta.direct = delta.last_top > scrollTop ? 'UP' : 'DOWN';
22+
delta.last_top = scrollTop;
23+
}
24+
};
25+
1526
Vue.component('virtual-list', {
1627

1728
props: {
@@ -38,7 +49,7 @@ Vue.component('virtual-list', {
3849
let viewHeight = cont.offsetHeight;
3950
let listHeight = listbox.offsetHeight;
4051

41-
this.recordDirect(scrollTop);
52+
saveDirect(scrollTop);
4253

4354
// scroll to top
4455
if (scrollTop === 0) {
@@ -56,15 +67,6 @@ Vue.component('virtual-list', {
5667
}
5768
}, 16, true, true),
5869

59-
recordDirect (scrollTop) {
60-
if (!delta.last_top) {
61-
delta.last_top = scrollTop;
62-
} else {
63-
delta.direct = delta.last_top > scrollTop ? 'UP' : 'DOWN';
64-
delta.last_top = scrollTop;
65-
}
66-
},
67-
6870
showNext () {
6971
delta.page_type = 'NEXT';
7072
this.$emit('bottom');
@@ -95,7 +97,7 @@ Vue.component('virtual-list', {
9597
}
9698

9799
return index >= (delta.start_index - this.pageCounts)
98-
&& index <= (delta.start_index - 1);
100+
&& index < delta.start_index;
99101
});
100102

101103
if (nowStartIndex !== udf) {

0 commit comments

Comments
 (0)