Blame view

src/views/demo/comp/scroll/VirtualScroll.vue 1.63 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">
陈文彬 authored
6
7
8
        <template v-slot="{ item }">
          <div class="virtual-scroll-demo__item">{{ item.title }}</div>
        </template>
9
      </VScroll>
陈文彬 authored
10
11
    </div>
12
    <Divider>即使不可见,也预先加载50条数据,防止空白</Divider>
陈文彬 authored
13
    <div class="virtual-scroll-demo-wrap">
14
      <VScroll :itemHeight="41" :items="data" :height="300" :width="300" :bench="50">
陈文彬 authored
15
16
17
        <template v-slot="{ item }">
          <div class="virtual-scroll-demo__item">{{ item.title }}</div>
        </template>
18
      </VScroll>
陈文彬 authored
19
    </div>
20
  </PageWrapper>
陈文彬 authored
21
22
23
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
24
  import { VScroll } from '/@/components/VirtualScroll/index';
陈文彬 authored
25
26

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