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

H
hdx 已提交
35
    methods: {
雪洛's avatar
雪洛 已提交
36 37 38
      test() {
        this.refresherTriggered = true
      },
H
hdx 已提交
39 40 41 42
      onRefresherrefresh(_ : RefresherEvent) {
        this.refresherrefresh = true
        console.log("onRefresherrefresh--------------下拉刷新触发")
        this.refresherTriggered = true
雪洛's avatar
雪洛 已提交
43
        this.refresherrefreshTimes++
H
hdx 已提交
44 45 46
        setTimeout(() => {
          this.refresherTriggered = false
        }, 1500)
47

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

<style>
H
hdx 已提交
67 68 69 70 71
  .container {
    display: flex;
    flex-direction: column;
    flex: 1;
  }
72

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

H
hdx 已提交
83 84 85 86 87 88 89
  .scroll-item {
    margin-left: 6px;
    margin-right: 6px;
    margin-top: 6px;
    background-color: #fff;
    border-radius: 4px;
  }
90

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