custom-tab-bar-tab1.uvue 1.2 KB
Newer Older
H
hdx 已提交
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
<template>
  <list-view ref="listView" class="list" :rebound="false" :scroll-y="true" @scrolltolower="loadData()"
    @scroll="onScroll">
    <list-item class="list-item" v-for="(item, index) in dataList" :key="index">
      <text class="title">{{item.title}}</text>
    </list-item>
  </list-view>
</template>

<script>
  type ListItem = {
    title : string
  }

  export default {
    data() {
      return {
        dataList: [] as ListItem[]
      }
    },
    created() {
      this.loadData()
    },
    methods: {
      loadData() {
        let index = this.dataList.length
        for (let i = 0; i < 10; i++) {
          this.dataList.push({
            title: index.toString(),
          } as ListItem)
          index++
        }
      },
      onScroll(e : ScrollEvent) {
        uni.$emit('tabchange', e.detail.scrollTop)
      },
      scrollTop(top : number) {
        (this.$refs["listView"] as Element).setAttribute('scrollTop', top)
      }
    }
  }
</script>

<style>
  .list {
    flex: 1;
    background-color: #ffffff;
  }

  .list-item {
    flex-direction: row;
    padding: 30px;
    border-bottom: 1px solid #dbdbdb;
  }

  .title {
    font-size: 16px;
    text-align: center;
  }
</style>