scroll-view-refresher.uvue 2.9 KB
Newer Older
1
<template>
H
hdx 已提交
2 3 4 5
  <view class="container">
    <page-head title="scroll-view 下拉刷新"></page-head>
    <scroll-view class="scroll" refresher-enabled=true :refresher-triggered="refresherTriggered"
      @refresherrefresh="onRefresherrefresh" @refresherabort="onRefresherabort" @refresherrestore="onRefresherrestore"
6
      @refresherpulling="onRefresherpulling" @scrolltolower="onScrolltolower" :show-scrollbar="showScrollbar">
H
hdx 已提交
7 8 9 10 11 12 13
      <view v-for="key in scrollData" :key="key">
        <view class="scroll-item">
          <text class="scroll-item-title">{{key}}</text>
        </view>
      </view>
    </scroll-view>
  </view>
14 15
</template>
<script>
H
hdx 已提交
16 17 18 19 20
  export default {
    data() {
      return {
        scrollData: [] as Array<string>,
        refresherTriggered: false,
21
        refresherrefresh: false,
雪洛's avatar
雪洛 已提交
22
        refresherrefreshTimes: 0,
23 24 25 26 27 28
        showScrollbar: false,
        // 自动化测试
        refresherrefreshTest:null as RefresherEvent|null,
        onRefresherabortTest:null as RefresherEvent|null,
        onRefresherrestoreTest:null as RefresherEvent|null,
        onRefresherpullingTest:null as RefresherEvent|null
H
hdx 已提交
29 30 31 32 33 34 35 36 37
      };
    },
    onLoad() {
      let lists : Array<string> = []
      for (let i = 0; i < 20; i++) {
        lists.push("item---" + i)
      }
      this.scrollData = lists
    },
38

H
hdx 已提交
39
    methods: {
40
      onRefresherrefresh(e : RefresherEvent) {
H
hdx 已提交
41 42
        this.refresherrefresh = true
        console.log("onRefresherrefresh--------------下拉刷新触发")
43
        this.refresherrefreshTest = e
H
hdx 已提交
44
        this.refresherTriggered = true
雪洛's avatar
雪洛 已提交
45
        this.refresherrefreshTimes++
H
hdx 已提交
46 47 48 49
        setTimeout(() => {
          this.refresherTriggered = false
        }, 1500)
      },
50
      onRefresherabort(e : RefresherEvent) {
H
hdx 已提交
51
        console.log("onRefresherabort------下拉刷新被中止")
52
        this.onRefresherabortTest = e
H
hdx 已提交
53
      },
54
      onRefresherrestore(e : RefresherEvent) {
H
hdx 已提交
55 56
        this.refresherrefresh = false
        console.log("onRefresherrestore------下拉刷新被复位")
57
        this.onRefresherrestoreTest = e
H
hdx 已提交
58 59
      },
      onRefresherpulling(e : RefresherEvent) {
60
        console.log("onRefresherpulling------拉刷新控件被下拉-dy=" + e.detail.dy)
61
        this.onRefresherpullingTest = e
H
hdx 已提交
62 63 64 65 66 67
      },
      onScrolltolower(e : ScrollToLowerEvent) {
        console.log("onScrolltolower 滚动到底部-----" + e.detail.direction)
      }
    }
  };
68 69 70
</script>

<style>
H
hdx 已提交
71 72 73 74 75
  .container {
    display: flex;
    flex-direction: column;
    flex: 1;
  }
76

H
hdx 已提交
77 78 79 80 81 82 83 84 85
  .scroll {
    background-color: #eee;
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    border-color: red;
  }
86

H
hdx 已提交
87 88 89 90 91 92 93
  .scroll-item {
    margin-left: 6px;
    margin-right: 6px;
    margin-top: 6px;
    background-color: #fff;
    border-radius: 4px;
  }
94

H
hdx 已提交
95 96 97 98 99 100 101
  .scroll-item-title {
    width: 100%;
    height: 60px;
    line-height: 60px;
    text-align: center;
    color: #555;
  }
102
</style>