custom-refresher.uvue 2.0 KB
Newer Older
1
<template>
2 3 4 5 6 7
  <scroll-view class="scroll-view"
      :refresher-enabled="true" :refresher-triggered="refresherTriggered" refresher-default-style="none"
      @refresherpulling="onRefresherpulling"
      @refresherrefresh="onRefresherrefresh"
      :refresher-threshold="refresherThreshold"
  >
8 9
    <view v-for="i in 20" class="content-item">
      <text class="text">item-{{i}}</text>
10 11 12
    </view>
    <refresh-box slot="refresher" :state="state" :pullingDistance="pullingDistance"></refresh-box>
  </scroll-view>
13 14 15 16 17 18 19 20 21 22
</template>

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

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

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

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

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