开始

话题详情页的,上拉加载
参考动态页的关注。底部也有上拉加载。
image.png
复制组件的引用
image.png

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

image.png

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

image.png

H5端-wjw

在我的H5端 要想显示最底部,必须要动态的计算出总的高度来,然后通过滚动条滚动到最底部。
image.png
给最外层的这个topic-detail-list加上 动态计算出来的高度。

  1. :style="{height: swiperheight+'px'}"

image.png

  1. swiperheight: 500,

image.png

  1. onLoad() {
  2. uni.getSystemInfo({
  3. success: (res) => {
  4. console.log('当前window高度和窗口高度');
  5. console.log(res.windowHeight);
  6. console.log(res.screenHeight);
  7. let height = res.windowHeight - uni.upx2px(100)
  8. this.swiperheight = height;
  9. }
  10. });
  11. },

继续

页面监听加载更多的事件
image.png
页面上拉触底事件的处理函数
image.png
复制news页面的loadMore方法
image.png

  1. // 上拉加载
  2. loadmore() {
  3. if (this.guanzhu.loadtext != "上拉加载更多") {
  4. return;
  5. }
  6. // 修改状态
  7. this.guanzhu.loadtext = "加载中...";
  8. // 获取数据
  9. setTimeout(() => {
  10. //获取完成
  11. let obj = {
  12. userpic: "../../static/demo/userpic/12.jpg",
  13. username: "哈哈",
  14. sex: 0, //0 男 1 女
  15. age: 25,
  16. isguanzhu: false,
  17. title: "我是标题",
  18. titlepic: "../../static/demo/datapic/13.jpg",
  19. video: false,
  20. share: false,
  21. path: "深圳 龙岗",
  22. sharenum: 20,
  23. commentnum: 30,
  24. goodnum: 20
  25. };
  26. this.guanzhu.list.push(obj);
  27. this.guanzhu.loadtext = "上拉加载更多";
  28. }, 1000);
  29. // this.guanzhu.loadtext="没有更多数据了";
  30. }

当前选中的tab的索引的数据
image.png

image.png

  1. // 上拉加载
  2. loadmore() {
  3. if (this.tablist[this.tabIndex].loadtext != "上拉加载更多") {
  4. return;
  5. }
  6. // 修改状态
  7. this.tablist[this.tabIndex].loadtext = "加载中...";
  8. // 获取数据
  9. setTimeout(() => {
  10. //获取完成
  11. let obj = {
  12. userpic: "../../static/demo/userpic/12.jpg",
  13. username: "哈哈",
  14. sex: 0, //0 男 1 女
  15. age: 25,
  16. isguanzhu: false,
  17. title: "我是标题",
  18. titlepic: "../../static/demo/datapic/13.jpg",
  19. video: false,
  20. share: false,
  21. path: "深圳 龙岗",
  22. sharenum: 20,
  23. commentnum: 30,
  24. goodnum: 20
  25. };
  26. this.tablist[this.tabIndex].list.push(obj);
  27. this.tablist[this.tabIndex].loadtext = "上拉加载更多";
  28. }, 1000);
  29. }

image.png
调用方法
image.png

  1. onReachBottom() {
  2. this.loadmore();
  3. },

image.png

本节代码

topic-detail.vue页面

  1. <template>
  2. <view>
  3. <!-- 话题介绍 -->
  4. <topic-info :item="topicInfo"></topic-info>
  5. <!-- tabbar切换 -->
  6. <swiper-tab-head :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap" scrollStyle="border-bottom:0;"
  7. scrollItemStyle="width:50%;">
  8. </swiper-tab-head>
  9. <view class="topic-detail-list" :style="{height: swiperheight+'px'}">
  10. <block v-for="(item,index) in tablist" :key="index">
  11. <template v-if="tabIndex==index">
  12. <block v-for="(list,listindex) in item.list" :key="listindex">
  13. <common-list :item="list" :index="listindex"></common-list>
  14. </block>
  15. <!-- 上拉加载 -->
  16. <load-more :loadtext="item.loadtext"></load-more>
  17. </template>
  18. </block>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import topicInfo from '@/components/topic/topic-info.vue';
  24. import swiperTabHead from '@/components/index/swiper-tab-head.vue';
  25. import commonList from '@/components/common/common-list.vue';
  26. import loadMore from '@/components/common/load-more.vue';
  27. export default {
  28. components: {
  29. topicInfo,
  30. swiperTabHead,
  31. commonList,
  32. commonList,
  33. loadMore
  34. },
  35. data() {
  36. return {
  37. swiperheight: 500,
  38. srcollTopValue: 0, // 默认是0
  39. topicInfo: {
  40. titlepic: "../../static/demo/topicpic/13.jpeg",
  41. title: "忆往事,敬余生",
  42. desc: "我是描述",
  43. totalnum: 1000,
  44. todaynum: 1000,
  45. },
  46. tabIndex: 0,
  47. tabBars: [{
  48. name: "默认",
  49. id: "moren"
  50. },
  51. {
  52. name: "最新",
  53. id: "zuixin"
  54. },
  55. ],
  56. tablist: [{
  57. loadtext: "上拉加载更多",
  58. list: [
  59. // 文字
  60. {
  61. userpic: "../../static/demo/userpic/12.jpg",
  62. username: "哈哈",
  63. sex: 0, //0 男 1 女
  64. age: 25,
  65. isguanzhu: false,
  66. title: "我是标题",
  67. titlepic: "",
  68. video: false,
  69. share: false,
  70. path: "深圳 龙岗",
  71. sharenum: 20,
  72. commentnum: 30,
  73. goodnum: 20
  74. },
  75. // 图文
  76. {
  77. userpic: "../../static/demo/userpic/12.jpg",
  78. username: "哈哈",
  79. sex: 0, //0 男 1 女
  80. age: 25,
  81. isguanzhu: false,
  82. title: "我是标题",
  83. titlepic: "../../static/demo/datapic/13.jpg",
  84. video: false,
  85. share: false,
  86. path: "深圳 龙岗",
  87. sharenum: 20,
  88. commentnum: 30,
  89. goodnum: 20
  90. },
  91. // 视频
  92. {
  93. userpic: "../../static/demo/userpic/12.jpg",
  94. username: "哈哈",
  95. sex: 0, //0 男 1 女
  96. age: 25,
  97. isguanzhu: false,
  98. title: "我是标题",
  99. titlepic: "../../static/demo/datapic/13.jpg",
  100. video: {
  101. looknum: "20w",
  102. long: "2:47"
  103. },
  104. share: false,
  105. path: "深圳 龙岗",
  106. sharenum: 20,
  107. commentnum: 30,
  108. goodnum: 20
  109. },
  110. ]
  111. },
  112. {
  113. loadtext: "上拉加载更多",
  114. list: [
  115. // 文字
  116. {
  117. userpic: "../../static/demo/userpic/12.jpg",
  118. username: "哈哈",
  119. sex: 0, //0 男 1 女
  120. age: 25,
  121. isguanzhu: false,
  122. title: "我是标题",
  123. titlepic: "",
  124. video: false,
  125. share: false,
  126. path: "深圳 龙岗",
  127. sharenum: 20,
  128. commentnum: 30,
  129. goodnum: 20
  130. },
  131. // 图文
  132. {
  133. userpic: "../../static/demo/userpic/12.jpg",
  134. username: "哈哈",
  135. sex: 0, //0 男 1 女
  136. age: 25,
  137. isguanzhu: false,
  138. title: "我是标题",
  139. titlepic: "../../static/demo/datapic/13.jpg",
  140. video: false,
  141. share: false,
  142. path: "深圳 龙岗",
  143. sharenum: 20,
  144. commentnum: 30,
  145. goodnum: 20
  146. },
  147. // 视频
  148. {
  149. userpic: "../../static/demo/userpic/12.jpg",
  150. username: "哈哈",
  151. sex: 0, //0 男 1 女
  152. age: 25,
  153. isguanzhu: false,
  154. title: "我是标题",
  155. titlepic: "../../static/demo/datapic/13.jpg",
  156. video: {
  157. looknum: "20w",
  158. long: "2:47"
  159. },
  160. share: false,
  161. path: "深圳 龙岗",
  162. sharenum: 20,
  163. commentnum: 30,
  164. goodnum: 20
  165. },
  166. ]
  167. },
  168. ]
  169. }
  170. },
  171. onLoad() {
  172. uni.getSystemInfo({
  173. success: (res) => {
  174. console.log('当前window高度和窗口高度');
  175. console.log(res.windowHeight);
  176. console.log(res.screenHeight);
  177. let height = res.windowHeight - uni.upx2px(100)
  178. this.swiperheight = height;
  179. }
  180. });
  181. },
  182. onReachBottom() {
  183. this.loadmore();
  184. },
  185. methods: {
  186. // tabbar点击事件
  187. tabtap(index) {
  188. // console.log(index);
  189. this.tabIndex = index;
  190. },
  191. // 上拉加载
  192. loadmore() {
  193. if (this.tablist[this.tabIndex].loadtext != "上拉加载更多") {
  194. return;
  195. }
  196. // 修改状态
  197. this.tablist[this.tabIndex].loadtext = "加载中...";
  198. // 获取数据
  199. setTimeout(() => {
  200. //获取完成
  201. let obj = {
  202. userpic: "../../static/demo/userpic/12.jpg",
  203. username: "哈哈",
  204. sex: 0, //0 男 1 女
  205. age: 25,
  206. isguanzhu: false,
  207. title: "我是标题",
  208. titlepic: "../../static/demo/datapic/13.jpg",
  209. video: false,
  210. share: false,
  211. path: "深圳 龙岗",
  212. sharenum: 20,
  213. commentnum: 30,
  214. goodnum: 20
  215. };
  216. this.tablist[this.tabIndex].list.push(obj);
  217. this.tablist[this.tabIndex].loadtext = "上拉加载更多";
  218. }, 1000);
  219. }
  220. }
  221. }
  222. </script>
  223. <style>
  224. </style>

结束