scroll-view-refresher.uvue 2.4 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,
22
        showScrollbar: false
H
hdx 已提交
23 24 25 26 27 28 29 30 31
      };
    },
    onLoad() {
      let lists : Array<string> = []
      for (let i = 0; i < 20; i++) {
        lists.push("item---" + i)
      }
      this.scrollData = lists
    },
32

H
hdx 已提交
33 34 35 36 37 38 39 40
    methods: {
      onRefresherrefresh(_ : RefresherEvent) {
        this.refresherrefresh = true
        console.log("onRefresherrefresh--------------下拉刷新触发")
        this.refresherTriggered = true
        setTimeout(() => {
          this.refresherTriggered = false
        }, 1500)
41

H
hdx 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
      },
      onRefresherabort(_ : RefresherEvent) {
        console.log("onRefresherabort------下拉刷新被中止")
      },
      onRefresherrestore(_ : RefresherEvent) {
        this.refresherrefresh = false
        console.log("onRefresherrestore------下拉刷新被复位")
      },
      onRefresherpulling(e : RefresherEvent) {
        console.log("onRefresherrestore------拉刷新控件被下拉-dy=" + e.detail.dy)
      },
      onScrolltolower(e : ScrollToLowerEvent) {
        console.log("onScrolltolower 滚动到底部-----" + e.detail.direction)
      }
    }
  };
58 59 60
</script>

<style>
H
hdx 已提交
61 62 63 64 65
  .container {
    display: flex;
    flex-direction: column;
    flex: 1;
  }
66

H
hdx 已提交
67 68 69 70 71 72 73 74 75
  .scroll {
    background-color: #eee;
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    border-color: red;
  }
76

H
hdx 已提交
77 78 79 80 81 82 83
  .scroll-item {
    margin-left: 6px;
    margin-right: 6px;
    margin-top: 6px;
    background-color: #fff;
    border-radius: 4px;
  }
84

H
hdx 已提交
85 86 87 88 89 90 91
  .scroll-item-title {
    width: 100%;
    height: 60px;
    line-height: 60px;
    text-align: center;
    color: #555;
  }
92
</style>