|
1
2
3
4
|
<template>
<div class="p-4 virtual-scroll-demo">
<Divider>基础滚动示例</Divider>
<div class="virtual-scroll-demo-wrap">
|
vben
authored
|
5
|
<VScroll :itemHeight="41" :items="data" :height="300" :width="300">
|
|
6
7
8
|
<template v-slot="{ item }">
<div class="virtual-scroll-demo__item">{{ item.title }}</div>
</template>
|
vben
authored
|
9
|
</VScroll>
|
|
10
11
|
</div>
|
nebv
authored
|
12
|
<Divider>即使不可见,也预先加载50条数据,防止空白</Divider>
|
|
13
|
<div class="virtual-scroll-demo-wrap">
|
vben
authored
|
14
|
<VScroll :itemHeight="41" :items="data" :height="300" :width="300" :bench="50">
|
|
15
16
17
|
<template v-slot="{ item }">
<div class="virtual-scroll-demo__item">{{ item.title }}</div>
</template>
|
vben
authored
|
18
|
</VScroll>
|
|
19
20
21
22
23
|
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
|
vben
authored
|
24
|
import { VScroll } from '/@/components/VirtualScroll/index';
|
|
25
26
27
28
29
30
31
32
33
34
35
36
|
import { Divider } from 'ant-design-vue';
const data: any[] = (() => {
const arr: any[] = [];
for (let index = 1; index < 20000; index++) {
arr.push({
title: '列表项' + index,
});
}
return arr;
})();
export default defineComponent({
|
vben
authored
|
37
|
components: { VScroll: VScroll, Divider },
|
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
setup() {
return { data: data };
},
});
</script>
<style lang="less" scoped>
.virtual-scroll-demo {
&-wrap {
display: flex;
margin: 0 30%;
background: #fff;
justify-content: center;
}
|
|
52
|
&__item {
|
|
53
54
55
56
57
58
59
|
height: 40px;
padding: 0 20px;
line-height: 40px;
border-bottom: 1px solid #ddd;
}
}
</style>
|