pull-down-refresh.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap uni-common-mt">
  5. <view style="font-size: 12px; color: #666;">注:PC 不支持下拉刷新</view>
  6. <view class="text" v-for="(num,index) in data" :key="index">list - {{num}}</view>
  7. <view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. title: '下拉刷新 + 加载更多',
  16. data: [],
  17. loadMoreText: "加载中...",
  18. showLoadMore: false,
  19. max: 0
  20. }
  21. },
  22. onLoad() {
  23. this.initData();
  24. },
  25. onUnload() {
  26. this.max = 0,
  27. this.data = [],
  28. this.loadMoreText = "加载更多",
  29. this.showLoadMore = false;
  30. },
  31. onReachBottom() {
  32. console.log("onReachBottom");
  33. if (this.max > 40) {
  34. this.loadMoreText = "没有更多数据了!"
  35. return;
  36. }
  37. this.showLoadMore = true;
  38. setTimeout(() => {
  39. this.setListData();
  40. }, 300);
  41. },
  42. onPullDownRefresh() {
  43. console.log('onPullDownRefresh');
  44. this.initData();
  45. },
  46. methods: {
  47. initData(){
  48. setTimeout(() => {
  49. this.max = 0;
  50. this.data = [];
  51. let data = [];
  52. this.max += 20;
  53. for (var i = this.max - 19; i < this.max + 1; i++) {
  54. data.push(i)
  55. }
  56. this.data = this.data.concat(data);
  57. uni.stopPullDownRefresh();
  58. }, 300);
  59. },
  60. setListData() {
  61. let data = [];
  62. this.max += 10;
  63. for (var i = this.max - 9; i < this.max + 1; i++) {
  64. data.push(i)
  65. }
  66. this.data = this.data.concat(data);
  67. }
  68. }
  69. }
  70. </script>
  71. <style>
  72. .text {
  73. margin: 16rpx 0;
  74. width:100%;
  75. background-color: #fff;
  76. height: 120rpx;
  77. line-height: 120rpx;
  78. text-align: center;
  79. color: #555;
  80. border-radius: 8rpx;
  81. }
  82. </style>