custom-refresher.uvue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <!-- #ifdef WEB -->
  3. <view>
  4. <!-- #endif -->
  5. <list-view class="list-view" :refresher-enabled="true" :refresher-triggered="refresherTriggered"
  6. refresher-default-style="none" @refresherpulling="onRefresherpulling" @refresherrefresh="onRefresherrefresh"
  7. @refresherrestore="onRefreshrestore" :refresher-threshold="refresherThreshold" refresher-max-drag-distance="200px">
  8. <sticky-header>
  9. <view class="header">
  10. <text>sticky header</text>
  11. </view>
  12. </sticky-header>
  13. <list-item v-for="i in 20" class="content-item">
  14. <text class="text">item-{{i}}</text>
  15. </list-item>
  16. <refresh-box slot="refresher" :state="state" :pullingDistance="pullingDistance"></refresh-box>
  17. </list-view>
  18. <!-- #ifdef WEB -->
  19. </view>
  20. <!-- #endif -->
  21. </template>
  22. <script>
  23. import refreshBox from './refresh-box/refresh-box.uvue';
  24. export default {
  25. components: { refreshBox },
  26. data() {
  27. return {
  28. refresherTriggered: false,
  29. refresherThreshold: 40,
  30. pullingDistance: 0,
  31. resetting: false
  32. }
  33. },
  34. computed: {
  35. state() : number {
  36. if (this.resetting) {
  37. return 3;
  38. }
  39. if (this.refresherTriggered) {
  40. return 2
  41. }
  42. if (this.pullingDistance > this.refresherThreshold) {
  43. return 1
  44. } else {
  45. return 0
  46. }
  47. }
  48. },
  49. methods: {
  50. onRefresherpulling(e : RefresherEvent) {
  51. // console.log('onRefresherpulling',e.detail.dy)
  52. this.pullingDistance = e.detail.dy
  53. },
  54. onRefresherrefresh() {
  55. this.refresherTriggered = true
  56. setTimeout(() => {
  57. this.refresherTriggered = false
  58. this.resetting = true
  59. }, 1500)
  60. },
  61. onRefreshrestore() {
  62. this.pullingDistance = 0
  63. this.resetting = false;
  64. }
  65. }
  66. }
  67. </script>
  68. <style>
  69. .list-view {
  70. flex: 1;
  71. background-color: #f5f5f5;
  72. }
  73. .header {
  74. justify-content: center;
  75. height: 50px;
  76. background-color: #f5f5f5;
  77. padding: 15px;
  78. }
  79. .content-item {
  80. padding: 15px;
  81. margin: 5px 0;
  82. background-color: #fff;
  83. border-radius: 5px;
  84. }
  85. .text {
  86. font-size: 14px;
  87. color: #666;
  88. line-height: 20px;
  89. }
  90. </style>