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

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

<style>
65 66 67 68 69
.scroll-view {
  flex: 1;
  padding: 5px 15px;
  background-color: #f5f5f5;
}
70

71 72 73 74 75 76
.content-item {
  padding: 15px;
  margin: 5px 0;
  background-color: #fff;
  border-radius: 5px;
}
xuty73419315's avatar
xuty73419315 已提交
77

78 79 80 81 82
.text {
  font-size: 14px;
  color: #666;
  line-height: 20px;
}
83

xuty73419315's avatar
xuty73419315 已提交
84
</style>