下拉刷新+加载更多

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

发表评论

表情:
评论列表 (有 0 条评论,512人围观)

还没有评论,来说两句吧...

相关阅读