开始

打开下拉刷新的功能
image.png
默认是关闭的
image.png

image.png

  1. "enablePullDownRefresh": true, // 开启下拉刷新

image.png

拉完后一直转圈。我们需要手动关闭他
image.png

image.png

image.png

image.png

  1. onPullDownRefresh() {
  2. },

image.png
手动关闭下拉刷新。
image.png
2秒后关闭下拉刷新
image.png

  1. onPullDownRefresh() {
  2. setTimeout(() => {
  3. uni.stopPullDownRefresh();
  4. }, 2000);
  5. },

image.png
2秒后关闭
image.png

模拟上拉刷新数据

三步
image.png

image.png

  1. onPullDownRefresh() {
  2. this.getdata();
  3. },
  1. // 上拉刷新
  2. getdata() {
  3. // 获取数据
  4. // 赋值
  5. // 关闭下拉刷新
  6. setTimeout(() => {
  7. uni.stopPullDownRefresh();
  8. }, 2000);
  9. },

复制一份数据
image.png
声明变量,假设这是刚获取的数据
image.png

image.png
变量放在setTimeOut里面
image.png

  1. // 上拉刷新
  2. getdata() {
  3. // 获取数据
  4. // 获取数据
  5. let arr = [
  6. // 文字
  7. {
  8. userpic: "../../static/demo/userpic/12.jpg",
  9. username: "哈哈111111",
  10. sex: 0, //0 男 1 女
  11. age: 25,
  12. isguanzhu: false,
  13. title: "我是标题11111",
  14. titlepic: "",
  15. video: false,
  16. share: false,
  17. path: "深圳 龙岗",
  18. sharenum: 20,
  19. commentnum: 30,
  20. goodnum: 20
  21. },
  22. // 图文
  23. {
  24. userpic: "../../static/demo/userpic/12.jpg",
  25. username: "哈哈",
  26. sex: 0, //0 男 1 女
  27. age: 25,
  28. isguanzhu: false,
  29. title: "我是标题",
  30. titlepic: "../../static/demo/datapic/13.jpg",
  31. video: false,
  32. share: false,
  33. path: "深圳 龙岗",
  34. sharenum: 20,
  35. commentnum: 30,
  36. goodnum: 20
  37. },
  38. // 视频
  39. {
  40. userpic: "../../static/demo/userpic/12.jpg",
  41. username: "哈哈",
  42. sex: 0, //0 男 1 女
  43. age: 25,
  44. isguanzhu: false,
  45. title: "我是标题",
  46. titlepic: "../../static/demo/datapic/13.jpg",
  47. video: {
  48. looknum: "20w",
  49. long: "2:47"
  50. },
  51. share: false,
  52. path: "深圳 龙岗",
  53. sharenum: 20,
  54. commentnum: 30,
  55. goodnum: 20
  56. },
  57. ];
  58. // 赋值
  59. this.tablist[this.tabIndex].list = arr;
  60. // 关闭下拉刷新
  61. setTimeout(() => {
  62. uni.stopPullDownRefresh();
  63. }, 2000);
  64. },

测试

image.png
新的测试数据
image.png

本节代码

  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. onPullDownRefresh() {
  183. this.getdata();
  184. },
  185. onReachBottom() {
  186. this.loadmore();
  187. },
  188. methods: {
  189. // 上拉刷新
  190. getdata() {
  191. // 获取数据
  192. // 获取数据
  193. let arr = [
  194. // 文字
  195. {
  196. userpic: "../../static/demo/userpic/12.jpg",
  197. username: "哈哈111111",
  198. sex: 0, //0 男 1 女
  199. age: 25,
  200. isguanzhu: false,
  201. title: "我是标题11111",
  202. titlepic: "",
  203. video: false,
  204. share: false,
  205. path: "深圳 龙岗",
  206. sharenum: 20,
  207. commentnum: 30,
  208. goodnum: 20
  209. },
  210. // 图文
  211. {
  212. userpic: "../../static/demo/userpic/12.jpg",
  213. username: "哈哈",
  214. sex: 0, //0 男 1 女
  215. age: 25,
  216. isguanzhu: false,
  217. title: "我是标题",
  218. titlepic: "../../static/demo/datapic/13.jpg",
  219. video: false,
  220. share: false,
  221. path: "深圳 龙岗",
  222. sharenum: 20,
  223. commentnum: 30,
  224. goodnum: 20
  225. },
  226. // 视频
  227. {
  228. userpic: "../../static/demo/userpic/12.jpg",
  229. username: "哈哈",
  230. sex: 0, //0 男 1 女
  231. age: 25,
  232. isguanzhu: false,
  233. title: "我是标题",
  234. titlepic: "../../static/demo/datapic/13.jpg",
  235. video: {
  236. looknum: "20w",
  237. long: "2:47"
  238. },
  239. share: false,
  240. path: "深圳 龙岗",
  241. sharenum: 20,
  242. commentnum: 30,
  243. goodnum: 20
  244. },
  245. ];
  246. // 赋值
  247. this.tablist[this.tabIndex].list = arr;
  248. // 关闭下拉刷新
  249. setTimeout(() => {
  250. uni.stopPullDownRefresh();
  251. }, 2000);
  252. },
  253. // tabbar点击事件
  254. tabtap(index) {
  255. // console.log(index);
  256. this.tabIndex = index;
  257. },
  258. // 上拉加载
  259. loadmore() {
  260. if (this.tablist[this.tabIndex].loadtext != "上拉加载更多") {
  261. return;
  262. }
  263. // 修改状态
  264. this.tablist[this.tabIndex].loadtext = "加载中...";
  265. // 获取数据
  266. setTimeout(() => {
  267. //获取完成
  268. let obj = {
  269. userpic: "../../static/demo/userpic/12.jpg",
  270. username: "哈哈",
  271. sex: 0, //0 男 1 女
  272. age: 25,
  273. isguanzhu: false,
  274. title: "我是标题",
  275. titlepic: "../../static/demo/datapic/13.jpg",
  276. video: false,
  277. share: false,
  278. path: "深圳 龙岗",
  279. sharenum: 20,
  280. commentnum: 30,
  281. goodnum: 20
  282. };
  283. this.tablist[this.tabIndex].list.push(obj);
  284. this.tablist[this.tabIndex].loadtext = "上拉加载更多";
  285. }, 1000);
  286. }
  287. }
  288. }
  289. </script>
  290. <style>
  291. </style>

结束