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

<script>
  import RefresherEvent from 'io.dcloud.uniapp.runtime.RefresherEvent';
  import refreshBox from './refresh-box/refresh-box.uvue';
  export default {
    components:{refreshBox},
    data() {
      return {
        refresherTriggered:false,
        refresherThreshold:40,
        pullingDistance:0
      }
    },
    computed:{
      state():number{
        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
      },
      onRefresherrefresh(){
        this.refresherTriggered = true
        setTimeout(()=>{
          this.refresherTriggered = false
DCloud_JSON's avatar
DCloud_JSON 已提交
50
        },1500)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
      },
      // onRefresherrestore(e:RefresherEvent){
      //   console.log('onRefresherrestore',e)
      // },
      // onRefresherabort(e:RefresherEvent){
      //   console.log('onRefresherabort',e)
      // },
    }
  }
</script>

<style>
  .scroll-view {
    flex: 1;
  }
  .item {
    height: 80px;
    justify-content: center;
  }
</style>