-
Notifications
You must be signed in to change notification settings - Fork 24
/
App.vue
84 lines (77 loc) · 2.22 KB
/
App.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
<div class="app">
<h1>vue-data-loading</h1>
<vue-data-loading :loading="loading" :completed="completed" :listens="['infinite-scroll', 'pull-down']" :init-scroll="true" @infinite-scroll="infiniteScroll" @pull-down="pullDown">
<div slot="pull-down-ready">ready to refresh</div>
<ul>
<li v-for="(item, index) in list" :key="index">测试专用填充数据: {{item}}</li>
</ul>
<div slot="infinite-scroll-loading">loading...</div>
<div slot="completed">completed!</div>
</vue-data-loading>
</div>
</template>
<script>
import VueDataLoading from '../src'
export default {
name: 'app',
components: {
VueDataLoading
},
data() {
return {
list: [],
loading: false,
completed: false,
page: 1,
}
},
methods: {
fetchData() {
this.loading = true
setTimeout(() => {
if (this.page > 3) {
this.completed = true
this.loading = false
return
}
const temp = []
for (let i = this.list.length + 1; i <= this.list.length + 50; i++) {
temp.push(i)
}
this.list = this.list.concat(temp)
this.loading = false
}, 1000)
},
pullUp() {
this.fetchData()
this.page++
},
pullDown() {
this.list = []
this.page = 1
this.completed = false
this.fetchData()
},
infiniteScroll() {
this.fetchData()
this.page++
},
},
created() {
// this.fetchData()
}
}
</script>
<style lang="scss">
.app {
max-width: 400px;
margin: 0 auto;
text-align: center;
ul {
margin: 0;
padding: 0;
list-style: none;
}
}
</style>