开始

参考话题详情页的代码
image.png

image.png

  1. import loadMore from '@/components/common/load-more.vue';
  2. loadMore

image.png

  1. loadtext:"上拉加载更多",

整个页面就一个列表数据,所以我们就写在data里面就可以了
image.png

image.png

  1. <!-- 上拉加载 -->
  2. <load-more :loadtext="loadtext"></load-more>

image.png
目前数据太少了。
image.png
多加一些数据 ,让数据出现滚动
image.png

  1. list:[
  2. {
  3. userpic:"../../static/demo/userpic/12.jpg",
  4. username:"昵称",
  5. time:"10:21",
  6. data:"我是信息",
  7. noreadnum:2
  8. },
  9. {
  10. userpic:"../../static/demo/userpic/12.jpg",
  11. username:"昵称",
  12. time:"10:21",
  13. data:"我是信息",
  14. noreadnum:0
  15. },
  16. {
  17. userpic:"../../static/demo/userpic/12.jpg",
  18. username:"昵称",
  19. time:"10:21",
  20. data:"我是信息",
  21. noreadnum:0
  22. },
  23. {
  24. userpic:"../../static/demo/userpic/12.jpg",
  25. username:"昵称",
  26. time:"10:21",
  27. data:"我是信息",
  28. noreadnum:11
  29. },
  30. {
  31. userpic:"../../static/demo/userpic/12.jpg",
  32. username:"昵称",
  33. time:"10:21",
  34. data:"我是信息",
  35. noreadnum:2
  36. },
  37. {
  38. userpic:"../../static/demo/userpic/12.jpg",
  39. username:"昵称",
  40. time:"10:21",
  41. data:"我是信息",
  42. noreadnum:0
  43. },
  44. {
  45. userpic:"../../static/demo/userpic/12.jpg",
  46. username:"昵称",
  47. time:"10:21",
  48. data:"我是信息",
  49. noreadnum:0
  50. },
  51. {
  52. userpic:"../../static/demo/userpic/12.jpg",
  53. username:"昵称",
  54. time:"10:21",
  55. data:"我是信息",
  56. noreadnum:11
  57. }
  58. ]

监听页面的滚动事件

image.png

  1. onReachBottom() {
  2. },

image.png

复制详情页的上拉加载的代码
image.png

image.png

image.png

image.png
触底 加载一条新的数据
image.png

动画效果

复制这里的动画效果
image.png

image.png

  1. <view class="paper-list u-f-ac animated fadeInLeft faster">

从左到右出现新数据
image.png

本节代码

  1. <template>
  2. <view class="body">
  3. <!-- 小纸条列表 -->
  4. <block v-for="(item,index) in list" :key="index">
  5. <paper-list :item="item" :index="index"></paper-list>
  6. </block>
  7. <!-- 上拉加载 -->
  8. <load-more :loadtext="loadtext"></load-more>
  9. </view>
  10. </template>
  11. <script>
  12. import paperList from '@/components/paper/paper-list.vue';
  13. import loadMore from '@/components/common/load-more.vue';
  14. export default {
  15. components: {
  16. paperList,
  17. loadMore
  18. },
  19. data() {
  20. return {
  21. loadtext: "上拉加载更多",
  22. list: [{
  23. userpic: "../../static/demo/userpic/12.jpg",
  24. username: "昵称",
  25. time: "10:21",
  26. data: "我是信息",
  27. noreadnum: 2
  28. },
  29. {
  30. userpic: "../../static/demo/userpic/12.jpg",
  31. username: "昵称",
  32. time: "10:21",
  33. data: "我是信息",
  34. noreadnum: 0
  35. },
  36. {
  37. userpic: "../../static/demo/userpic/12.jpg",
  38. username: "昵称",
  39. time: "10:21",
  40. data: "我是信息",
  41. noreadnum: 0
  42. },
  43. {
  44. userpic: "../../static/demo/userpic/12.jpg",
  45. username: "昵称",
  46. time: "10:21",
  47. data: "我是信息",
  48. noreadnum: 11
  49. },
  50. {
  51. userpic: "../../static/demo/userpic/12.jpg",
  52. username: "昵称",
  53. time: "10:21",
  54. data: "我是信息",
  55. noreadnum: 2
  56. },
  57. {
  58. userpic: "../../static/demo/userpic/12.jpg",
  59. username: "昵称",
  60. time: "10:21",
  61. data: "我是信息",
  62. noreadnum: 0
  63. },
  64. {
  65. userpic: "../../static/demo/userpic/12.jpg",
  66. username: "昵称",
  67. time: "10:21",
  68. data: "我是信息",
  69. noreadnum: 0
  70. },
  71. {
  72. userpic: "../../static/demo/userpic/12.jpg",
  73. username: "昵称",
  74. time: "10:21",
  75. data: "我是信息",
  76. noreadnum: 11
  77. }
  78. ]
  79. }
  80. },
  81. // 监听下拉刷新
  82. onPullDownRefresh() {
  83. this.getdata()
  84. },
  85. onReachBottom() {
  86. this.loadmore();
  87. },
  88. methods: {
  89. // 上拉加载
  90. loadmore() {
  91. if (this.loadtext != "上拉加载更多") {
  92. return;
  93. }
  94. // 修改状态
  95. this.loadtext = "加载中...";
  96. // 获取数据
  97. setTimeout(() => {
  98. //获取完成
  99. let obj = {
  100. userpic: "../../static/demo/userpic/12.jpg",
  101. username: "昵称",
  102. time: "10:21",
  103. data: "我是信息",
  104. noreadnum: 11
  105. };
  106. this.list.push(obj);
  107. this.loadtext = "上拉加载更多";
  108. }, 1000);
  109. //this.loadtext="没有更多数据了";
  110. },
  111. // 获取数据
  112. getdata() {
  113. setTimeout(() => {
  114. // 服务器获取数据
  115. let arr = [{
  116. userpic: "../../static/demo/userpic/12.jpg",
  117. username: "昵称1111",
  118. time: "10:21",
  119. data: "我是信息",
  120. noreadnum: 2
  121. },
  122. {
  123. userpic: "../../static/demo/userpic/12.jpg",
  124. username: "昵称222",
  125. time: "10:21",
  126. data: "我是信息",
  127. noreadnum: 0
  128. },
  129. {
  130. userpic: "../../static/demo/userpic/12.jpg",
  131. username: "昵称333",
  132. time: "10:21",
  133. data: "我是信息",
  134. noreadnum: 0
  135. },
  136. {
  137. userpic: "../../static/demo/userpic/12.jpg",
  138. username: "昵称444",
  139. time: "10:21",
  140. data: "我是信息",
  141. noreadnum: 11
  142. }
  143. ];
  144. // 赋值
  145. this.list = arr;
  146. // 关闭下拉刷新
  147. uni.stopPullDownRefresh();
  148. }, 2000);
  149. }
  150. }
  151. }
  152. </script>
  153. <style>
  154. .body {
  155. padding: 0 20upx;
  156. }
  157. </style>

结束