pull-down-refresh.vue 1.6 KB

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