Blame view

src/views/demo/comp/scroll/VirtualScroll.vue 1.7 KB
陈文彬 authored
1
<template>
2
  <PageWrapper class="virtual-scroll-demo">
陈文彬 authored
3
4
    <Divider>基础滚动示例</Divider>
    <div class="virtual-scroll-demo-wrap">
5
      <VScroll :itemHeight="41" :items="data" :height="300" :width="300">
6
7
8
9
        <template #default="{ item }">
          <div class="virtual-scroll-demo__item">
            {{ item.title }}
          </div>
陈文彬 authored
10
        </template>
11
      </VScroll>
陈文彬 authored
12
13
    </div>
14
    <Divider>即使不可见,也预先加载50条数据,防止空白</Divider>
陈文彬 authored
15
    <div class="virtual-scroll-demo-wrap">
16
      <VScroll :itemHeight="41" :items="data" :height="300" :width="300" :bench="50">
17
18
19
20
        <template #default="{ item }">
          <div class="virtual-scroll-demo__item">
            {{ item.title }}
          </div>
陈文彬 authored
21
        </template>
22
      </VScroll>
陈文彬 authored
23
    </div>
24
  </PageWrapper>
陈文彬 authored
25
26
27
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
28
  import { VScroll } from '/@/components/VirtualScroll/index';
陈文彬 authored
29
30

  import { Divider } from 'ant-design-vue';
31
  import { PageWrapper } from '/@/components/Page';
32
vben authored
33
34
  const data = (() => {
    const arr: any[] = [];
陈文彬 authored
35
36
37
38
39
40
41
42
    for (let index = 1; index < 20000; index++) {
      arr.push({
        title: '列表项' + index,
      });
    }
    return arr;
  })();
  export default defineComponent({
43
    components: { VScroll: VScroll, Divider, PageWrapper },
陈文彬 authored
44
45
46
47
48
49
50
51
52
    setup() {
      return { data: data };
    },
  });
</script>
<style lang="less" scoped>
  .virtual-scroll-demo {
    &-wrap {
      display: flex;
vben authored
53
      justify-content: center;
陈文彬 authored
54
      margin: 0 30%;
55
      background-color: @component-background;
陈文彬 authored
56
57
    }
陈小婷 authored
58
    &__item {
陈文彬 authored
59
60
      height: 40px;
      padding: 0 20px;
Vben authored
61
      border-bottom: 1px solid @border-color-base;
vben authored
62
      line-height: 40px;
陈文彬 authored
63
64
65
    }
  }
</style>