custom-pull-page.uvue 3.3 KB
Newer Older
1
<template>
2 3 4 5
  <view class="root">
    <view class="top-box">
      <text class="top-box-text">可通过slot自定义,上拉加载下来刷新效果示例</text>
    </view>
6 7 8 9 10 11 12

    <custom-pull :height="300" width="750rpx" :refreshBoxHeight="60" :refreshThreshold="60" :refreshHoldHeight="60"
      :loadingBoxHeight="30" :loadingThreshold="20" :loadingHoldHeight="30" @loading="loading" @refresh="refresh"
      ref="custom-pull" class="custom-pull">

      <template v-slot:refresh-box="scope">
        <view class="refresh-box">
13
          <image class="logo" src="/static/uni.png" mode="widthFix"></image>
14 15 16
          <text class="tip-text" v-if="scope.get('refreshState')== 0">继续下拉执行刷新(slot)</text>
          <text class="tip-text" v-if="scope.get('refreshState')== 1">释放立即刷新</text>
          <text class="tip-text" v-if="scope.get('refreshState')== 2">刷新中</text>
17
          <text class="tip-text" v-if="scope.get('refreshState')== 3">刷新完成</text>
18 19 20 21 22 23 24 25 26 27 28 29 30 31
          <!-- 可基于拖动距离实现互动性更加强的效果 -->
          <!-- <text class="tip-text">拖动的距离:{{scope.get('pullingDistance')}}</text> -->
        </view>
      </template>

      <view v-for="i in 8" class="item">
        item-{{i}}
      </view>

      <template v-slot:loading-box="scope">
        <view class="loading-box">
          <text class="tip-text" v-if="scope.get('loadingState')== 0">继续上拉加载更多(slot)</text>
          <text class="tip-text" v-if="scope.get('loadingState')== 1">释放立即加载更多</text>
          <text class="tip-text" v-if="scope.get('loadingState')== 2">加载中...</text>
32
          <text class="tip-text" v-if="scope.get('loadingState')== 3">加载完成</text>
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
          <!-- 可基于拖动距离实现互动性更加强的效果 -->
          <!-- <text>拖动的距离:{{scope.get('pullingDistance')}}</text> -->
        </view>
      </template>

    </custom-pull>

  </view>
</template>

<script>
  import customPull from './custom-pull/custom-pull.uvue';

  export default {
    components: {
      customPull
    },
    data() {
      return {
      }
    },
54 55
    onReady() {
      // console.log('this.$refs["custom-pull"]', this.$refs["custom-pull"] as ComponentPublicInstance);
56 57 58 59
    },
    methods: {
      loading() {
        setTimeout(() => {
60
          (this.$refs["custom-pull"] as ComponentPublicInstance).$callMethod('endLoading')
61 62 63 64
        }, 1000);
      },
      refresh() {
        setTimeout(() => {
65
          (this.$refs["custom-pull"] as ComponentPublicInstance).$callMethod('endRefresh')
66 67 68 69 70 71 72 73 74 75
        }, 1000);
      }
    }
  }
</script>

<style scoped>
  .root {
    flex: 1;
    background-color: #FFF;
76 77 78 79 80 81 82
  }
  .top-box{
    padding: 15px 5px;
  }
  .top-box-text{
    font-size: 14px;
    color: #888;
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
  }

  .custom-pull {
    border: 1px solid #efefef;
  }

  .refresh-box,
  .loading-box {
    background-color: #efefef;
    justify-content: center;
    align-items: center;
  }

  .logo {
    width: 30px;
98
    height: 30px;
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    margin-top: 3px;
  }

  .item {
    height: 80px;
    border-top: 1px solid #efefef;
    justify-content: center;
  }

  .tip-text {
    color: #888;
    font-size: 12px;
    padding: 2px 0;
  }
</style>