scroll-view-refresher-props.uvue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="page-scroll-view">
  3. <page-head title="下拉刷新的scroll-view属性示例"></page-head>
  4. <view class="uni-margin-wrap">
  5. <scroll-view direction="vertical" :refresher-enabled="refresherEnabled" :refresher-threshold="refresherThreshold"
  6. :refresher-default-style="refresherDefaultStyle" :refresher-background="refresherBackground"
  7. :refresher-triggered="refresherTriggered" @refresherpulling="refresherpulling"
  8. @refresherrefresh="refresherrefresh" @refresherrestore="refresherrestore" @refresherabort="refresherabort"
  9. style="width: 100%;height: 100%;">
  10. <view class="item" :id="item.id" v-for="(item,_) in items">
  11. <text class="uni-text">{{item.label}}</text>
  12. </view>
  13. </scroll-view>
  14. </view>
  15. <scroll-view class="uni-list" style="padding-top: 16px;" :showScrollbar="true">
  16. <view class="uni-list-cell-padding">
  17. <text class="refresher-tips">**下拉刷新的属性设置需要先打开下拉刷新开关**</text>
  18. </view>
  19. <view class="uni-list-cell uni-list-cell-padding">
  20. <text>是否开启下拉刷新</text>
  21. <switch :checked="refresherEnabled" @change="handleTrunOnRefresher"></switch>
  22. </view>
  23. <view class="uni-list-cell uni-list-cell-padding">
  24. <text>设置下拉刷新状态</text>
  25. <switch :disabled="!refresherEnabled" :checked="refresherTriggered"
  26. @change="refresherTriggered=!refresherTriggered"></switch>
  27. </view>
  28. <view class="uni-list-cell uni-list-cell-padding">
  29. <text>设置下拉刷新阈值</text>
  30. <input class="uni-list-cell-input" :disabled="!refresherEnabled" :value="refresherThreshold" type="number"
  31. @input="handleRefresherThresholdInput" />
  32. </view>
  33. <view class="uni-list-cell uni-list-cell-padding">
  34. <text>设置下拉刷新区域背景颜色</text>
  35. <input class="uni-list-cell-input" :disabled="!refresherEnabled" :value="refresherBackground"
  36. @input="handleRefresherBackground" />
  37. </view>
  38. <view class="uni-list-cell-padding">
  39. <text>设置下拉刷新默认样式</text>
  40. <view class="switch-refresher-group">
  41. <button class="switch-refresher-style" type="primary" size="mini"
  42. @click="refresherDefaultStyle = `none`">none</button>
  43. <button class="switch-refresher-style" type="primary" size="mini"
  44. @click="refresherDefaultStyle = `black`">black</button>
  45. <button class="switch-refresher-style" type="primary" size="mini"
  46. @click="refresherDefaultStyle = `white`">white</button>
  47. </view>
  48. </view>
  49. </scroll-view>
  50. </view>
  51. </template>
  52. <script>
  53. type Item = {
  54. id : string,
  55. label : string,
  56. }
  57. export default {
  58. data() {
  59. return {
  60. items: [] as Item[],
  61. refresherEnabled: true,
  62. refresherTriggered: false,
  63. refresherThreshold: 45,
  64. refresherDefaultStyle: "black",
  65. refresherBackground: "transparent",
  66. }
  67. },
  68. onLoad() {
  69. for (let i = 0; i < 10; i++) {
  70. const item = {
  71. id: "item" + i,
  72. label: "item" + i,
  73. } as Item;
  74. this.items.push(item);
  75. }
  76. },
  77. methods: {
  78. handleTrunOnRefresher() {
  79. this.refresherTriggered = false;
  80. //不能同时关闭下拉状态和关闭下拉刷新。
  81. setTimeout(() => {
  82. this.refresherEnabled = !this.refresherEnabled;
  83. }, 0)
  84. },
  85. handleRefresherThresholdInput(e : InputEvent) {
  86. const value = e.detail.value;
  87. if (value == "") {
  88. this.refresherThreshold = 45;
  89. } else {
  90. this.refresherThreshold = parseInt(e.detail.value);
  91. }
  92. },
  93. handleRefresherBackground(e : InputEvent) {
  94. const value = e.detail.value;
  95. this.refresherBackground = value;
  96. },
  97. //响应事件
  98. refresherpulling() {
  99. console.log("下拉刷新控件被下拉");
  100. },
  101. refresherrefresh() {
  102. console.log("下拉刷新被触发");
  103. this.refresherTriggered = true;
  104. //不能同时关闭下拉状态和关闭下拉刷新。
  105. setTimeout(() => {
  106. this.refresherTriggered = false;
  107. }, 1500)
  108. },
  109. refresherrestore() {
  110. console.log("下拉刷新被复位");
  111. },
  112. refresherabort() {
  113. console.log("下拉刷新被中止");
  114. }
  115. }
  116. }
  117. </script>
  118. <style>
  119. .uni-margin-wrap {
  120. height: 200px;
  121. margin: 0 25px 25px 25px;
  122. }
  123. .item {
  124. justify-content: center;
  125. align-items: center;
  126. height: 200px;
  127. width: 100%;
  128. background-color: azure;
  129. border-width: 1px;
  130. border-style: solid;
  131. border-color: chocolate;
  132. }
  133. .refresher-tips {
  134. font-size: 12px;
  135. text-align: center;
  136. color: red;
  137. }
  138. .uni-text {
  139. color: black;
  140. font-size: 50px;
  141. }
  142. .uni-list {
  143. flex: 1;
  144. }
  145. .uni-list-cell-input {
  146. max-width: 100px;
  147. border: 1px solid #ccc;
  148. text-align: center;
  149. }
  150. .switch-refresher-group {
  151. flex-direction: row;
  152. margin-top: 5px;
  153. }
  154. .switch-refresher-style {
  155. padding: 2px 10px;
  156. margin-right: 5px;
  157. }
  158. </style>