custom-tab-bar-tab1.uvue 1.8 KB
Newer Older
H
hdx 已提交
1
<template>
2
  <scroll-view ref="listView" class="list" :rebound="false" :scroll-with-animation="true" :scroll-y="true" :scroll-top="newScrollTop" @scrolltolower="loadData()"
H
hdx 已提交
3
    @scroll="onScroll">
雪洛's avatar
雪洛 已提交
4
    <view class="list-item" v-for="(item, index) in dataList" :key="index">
5 6 7 8 9
      <!-- <text class="title">{{item.title}}</text> -->
      <view class="cell-item">
        <text class="title">内容:{{item.title}}</text>
        <input class="title" style="margin-top: 8px;" placeholder="备注:"/>
      </view>
雪洛's avatar
雪洛 已提交
10 11
    </view>
  </scroll-view>
H
hdx 已提交
12 13 14 15 16 17 18 19 20 21
</template>

<script>
  type ListItem = {
    title : string
  }

  export default {
    data() {
      return {
22 23 24
        dataList: [] as ListItem[],
        oldScrollTop: 0,
        newScrollTop: 0
H
hdx 已提交
25 26 27 28
      }
    },
    created() {
      this.loadData()
W
wanganxp 已提交
29
      // console.log("tab1 created");
H
hdx 已提交
30 31 32 33
    },
    methods: {
      loadData() {
        let index = this.dataList.length
雪洛's avatar
雪洛 已提交
34
        for (let i = 0; i < 20; i++) {
H
hdx 已提交
35 36 37 38 39 40 41 42
          this.dataList.push({
            title: index.toString(),
          } as ListItem)
          index++
        }
      },
      onScroll(e : ScrollEvent) {
        uni.$emit('tabchange', e.detail.scrollTop)
43
        this.oldScrollTop = e.detail.scrollTop
H
hdx 已提交
44 45
      },
      scrollTop(top : number) {
46
        // (this.$refs["listView"] as UniElement).scrollTop = top
W
wanganxp 已提交
47
        // console.log("tab1 to top");
48 49 50 51
        this.newScrollTop = this.oldScrollTop
        this.$nextTick(() => {
          this.newScrollTop = top
        })
H
hdx 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
      }
    }
  }
</script>

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

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

  .title {
    font-size: 16px;
71 72 73 74 75 76
    text-align: left;
  }

  .cell-item {
    display: flex;
    flex-direction: column;
H
hdx 已提交
77
  }
雪洛's avatar
雪洛 已提交
78
</style>