-
Notifications
You must be signed in to change notification settings - Fork 485
/
Scroll.vue
67 lines (57 loc) · 1.58 KB
/
Scroll.vue
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
<template>
<div class="page has-navbar" v-nav="{title: '下拉刷新、无限加载', showBackButton: true}">
<scroll class="page-content"
:on-refresh="onRefresh"
:on-infinite="onInfinite">
<item v-for="(item, index) in items" :key="index" @click.native="onItemClick(index)" :class="{'item-stable': index % 2 == 0}">
{{ item }}
</item>
<div v-if="infiniteCount >= 2" slot="infinite" class="text-center">没有更多数据</div>
</scroll>
</div>
</template>
<script>
export default {
data () {
return {
items: [],
infiniteCount: 0
}
},
mounted() {
for (let i = 1; i <= 20; i++) {
this.items.push(i + ' - keep walking, be 2 with you.')
}
this.top = 1
this.bottom = 20
},
methods: {
onRefresh(done) {
setTimeout(() => {
let start = this.top - 1
for (let i = start; i > start - 10; i--) {
this.items.splice(0, 0, i + ' - keep walking, be 2 with you.')
}
this.top = this.top - 10;
done()
}, 1500)
},
onInfinite(done) {
setTimeout(() => {
if (this.infiniteCount < 2) {
let start = this.bottom + 1
for (let i = start; i < start + 10; i++) {
this.items.push(i + ' - keep walking, be 2 with you.')
}
this.bottom = this.bottom + 10;
this.infiniteCount++
}
done()
}, 1500)
},
onItemClick(index) {
console.log(index)
}
}
}
</script>