custom-tab-bar-tab1.uvue 1.2 KB
Newer Older
H
hdx 已提交
1
<template>
雪洛's avatar
雪洛 已提交
2
  <scroll-view ref="listView" class="list" :rebound="false" :scroll-with-animation="true" :scroll-y="true" @scrolltolower="loadData()"
H
hdx 已提交
3
    @scroll="onScroll">
雪洛's avatar
雪洛 已提交
4
    <view class="list-item" v-for="(item, index) in dataList" :key="index">
H
hdx 已提交
5
      <text class="title">{{item.title}}</text>
雪洛's avatar
雪洛 已提交
6 7
    </view>
  </scroll-view>
H
hdx 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
</template>

<script>
  type ListItem = {
    title : string
  }

  export default {
    data() {
      return {
        dataList: [] as ListItem[]
      }
    },
    created() {
      this.loadData()
    },
    methods: {
      loadData() {
        let index = this.dataList.length
雪洛's avatar
雪洛 已提交
27
        for (let i = 0; i < 20; i++) {
H
hdx 已提交
28 29 30 31 32 33 34 35 36 37
          this.dataList.push({
            title: index.toString(),
          } as ListItem)
          index++
        }
      },
      onScroll(e : ScrollEvent) {
        uni.$emit('tabchange', e.detail.scrollTop)
      },
      scrollTop(top : number) {
38
        (this.$refs["listView"] as Element).scrollTop = top
H
hdx 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
      }
    }
  }
</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;
  }
雪洛's avatar
雪洛 已提交
60
</style>