scroll-view-custom-refresher-props.uvue 1.7 KB
Newer Older
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6 7 8 9 10
  <scroll-view style="flex:1;" :refresher-enabled="true" :refresher-triggered="refresherTriggered"
    refresher-default-style="none" @refresherpulling="onRefresherpulling" @refresherrefresh="onRefresherrefresh"
    @refresherrestore="onRefreshrestore" refresher-max-drag-distance="200px">
    <view style="height: 25px;"></view>
    <view v-for="i in 20" class="content-item">
      <text class="text">item-{{i}}</text>
    </view>
    <refresh-box slot="refresher" :state="state"></refresh-box>
  </scroll-view>
11 12 13
</template>

<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
14 15 16 17 18 19 20 21
  import refreshBox from './refresh-box/refresh-box.uvue';
  export default {
    components: { refreshBox },
    data() {
      return {
        refresherTriggered: false,
        pullingDistance: 0,
        resetting: false
22
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    },
    computed: {
      state() : number {
        if (this.resetting) {
          return 3;
        }
        if (this.refresherTriggered) {
          return 2
        }
        if (this.pullingDistance > 45) {
          return 1
        } else {
          return 0;
        }
      }
    },
    methods: {
      onRefresherpulling(e : RefresherEvent) {
        this.pullingDistance = e.detail.dy;
      },
      onRefresherrefresh() {
        this.refresherTriggered = true
        setTimeout(() => {
          this.refresherTriggered = false
          this.resetting = true;
        }, 1500)
      },
      onRefreshrestore() {
        this.pullingDistance = 0
        this.resetting = false;
      }
    }
  }
56 57 58
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
59 60 61 62 63 64
  .content-item {
    padding: 15px;
    margin: 5px 0;
    background-color: #fff;
    border-radius: 5px;
  }
65

DCloud-WZF's avatar
DCloud-WZF 已提交
66 67 68 69 70
  .text {
    font-size: 14px;
    color: #666;
    line-height: 20px;
  }
71
</style>