开始

实现tab切换
image.png
参考这里 topic-detail.vue页面。
image.png

把tablist数据也复制过来
image.png

  1. tablist: [{
  2. loadtext: "上拉加载更多",
  3. list: [
  4. // 文字
  5. {
  6. userpic: "../../static/demo/userpic/12.jpg",
  7. username: "哈哈",
  8. sex: 0, //0 男 1 女
  9. age: 25,
  10. isguanzhu: false,
  11. title: "我是标题",
  12. titlepic: "",
  13. video: false,
  14. share: false,
  15. path: "深圳 龙岗",
  16. sharenum: 20,
  17. commentnum: 30,
  18. goodnum: 20
  19. },
  20. // 图文
  21. {
  22. userpic: "../../static/demo/userpic/12.jpg",
  23. username: "哈哈",
  24. sex: 0, //0 男 1 女
  25. age: 25,
  26. isguanzhu: false,
  27. title: "我是标题",
  28. titlepic: "../../static/demo/datapic/13.jpg",
  29. video: false,
  30. share: false,
  31. path: "深圳 龙岗",
  32. sharenum: 20,
  33. commentnum: 30,
  34. goodnum: 20
  35. },
  36. // 视频
  37. {
  38. userpic: "../../static/demo/userpic/12.jpg",
  39. username: "哈哈",
  40. sex: 0, //0 男 1 女
  41. age: 25,
  42. isguanzhu: false,
  43. title: "我是标题",
  44. titlepic: "../../static/demo/datapic/13.jpg",
  45. video: {
  46. looknum: "20w",
  47. long: "2:47"
  48. },
  49. share: false,
  50. path: "深圳 龙岗",
  51. sharenum: 20,
  52. commentnum: 30,
  53. goodnum: 20
  54. },
  55. ]
  56. },
  57. {
  58. loadtext: "上拉加载更多",
  59. list: [
  60. // 文字
  61. {
  62. userpic: "../../static/demo/userpic/12.jpg",
  63. username: "哈哈",
  64. sex: 0, //0 男 1 女
  65. age: 25,
  66. isguanzhu: false,
  67. title: "我是标题",
  68. titlepic: "",
  69. video: false,
  70. share: false,
  71. path: "深圳 龙岗",
  72. sharenum: 20,
  73. commentnum: 30,
  74. goodnum: 20
  75. },
  76. // 图文
  77. {
  78. userpic: "../../static/demo/userpic/12.jpg",
  79. username: "哈哈",
  80. sex: 0, //0 男 1 女
  81. age: 25,
  82. isguanzhu: false,
  83. title: "我是标题",
  84. titlepic: "../../static/demo/datapic/13.jpg",
  85. video: false,
  86. share: false,
  87. path: "深圳 龙岗",
  88. sharenum: 20,
  89. commentnum: 30,
  90. goodnum: 20
  91. },
  92. // 视频
  93. {
  94. userpic: "../../static/demo/userpic/12.jpg",
  95. username: "哈哈",
  96. sex: 0, //0 男 1 女
  97. age: 25,
  98. isguanzhu: false,
  99. title: "我是标题",
  100. titlepic: "../../static/demo/datapic/13.jpg",
  101. video: {
  102. looknum: "20w",
  103. long: "2:47"
  104. },
  105. share: false,
  106. path: "深圳 龙岗",
  107. sharenum: 20,
  108. commentnum: 30,
  109. goodnum: 20
  110. },
  111. ]
  112. },
  113. ]

我们有3个tab。第一个tab默认显示userinfo
image.png
内容就是我们之前封装的common-list是差不多的。
image.png

image.png

  1. import commonList from '@/components/@/components/common/common-list.vue';
  2. commonList

上拉加载组件。
image.png

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

image.png

移植上拉加载

image.png

  1. // 上拉触底事件
  2. onReachBottom() {
  3. this.loadmore();
  4. },

还要复制loadmore。复制过来基本不需要修改。
image.png

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

image.png

image.png

本节代码

  1. <template>
  2. <view>
  3. <!-- 背景图 + 用户基本信息 -->
  4. <user-space-head :userinfo="userinfo"></user-space-head>
  5. <!-- 统计 -->
  6. <view class="user-space-data">
  7. <home-data :homedata="spacedata"></home-data>
  8. </view>
  9. <view class="height:20upx;background:F4F4F4;"></view>
  10. <!-- tabbar切换 -->
  11. <swiper-tab-head :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap" scrollStyle="border-bottom:0;"
  12. scrollItemStyle="width:33%;">
  13. </swiper-tab-head>
  14. <block v-for="(item,index) in tablist" :key="index">
  15. <template v-if="tabIndex==0">
  16. <!-- 主页 -->
  17. <user-space-userinfo :userinfo="userinfo"></user-space-userinfo>
  18. </template>
  19. <template v-else-if="tabIndex==index">
  20. <block v-for="(list,listindex) in item.list" :key="listindex">
  21. <common-list :item="list" :index="listindex"></common-list>
  22. </block>
  23. <!-- 上拉加载 -->
  24. <load-more :loadtext="item.loadtext"></load-more>
  25. </template>
  26. </block>
  27. </view>
  28. </template>
  29. <script>
  30. import userSpaceHead from '@/components/user-space/user-space-head.vue';
  31. import swiperTabHead from '@/components/index/swiper-tab-head.vue';
  32. import homeData from '@/components/home/home-data.vue';
  33. import userSpaceUserinfo from '@/components/user-space/user-space-userinfo.vue';
  34. import commonList from '@/components/common/common-list.vue';
  35. import loadMore from '@/components/common/load-more.vue';
  36. export default {
  37. components: {
  38. userSpaceHead,
  39. homeData,
  40. swiperTabHead,
  41. userSpaceUserinfo,
  42. commonList,
  43. loadMore
  44. },
  45. data() {
  46. return {
  47. tabIndex: 0,
  48. tabBars: [{
  49. name: "主页",
  50. id: "zhuye"
  51. },
  52. {
  53. name: "糗事",
  54. id: "qiushi"
  55. }, {
  56. name: "动态",
  57. id: "dongtai"
  58. },
  59. ],
  60. userinfo: {
  61. bgimg: 1,
  62. userpic: '../../static/demo/userpic/11.jpg',
  63. username: '昵称',
  64. sex: 0,
  65. age: 20,
  66. isguanzhu: false,
  67. regtime: '2019-04-11',
  68. id: 1213,
  69. birthday: '1987-02-07',
  70. job: 'IT',
  71. path: '广东广州',
  72. qg: '已婚'
  73. },
  74. spacedata: [{
  75. name: "获赞",
  76. num: '10k'
  77. },
  78. {
  79. name: "关注",
  80. num: 0
  81. },
  82. {
  83. name: "粉丝",
  84. num: 0
  85. }
  86. ],
  87. tablist: [{
  88. loadtext: "上拉加载更多",
  89. list: [
  90. // 文字
  91. {
  92. userpic: "../../static/demo/userpic/12.jpg",
  93. username: "哈哈",
  94. sex: 0, //0 男 1 女
  95. age: 25,
  96. isguanzhu: false,
  97. title: "我是标题",
  98. titlepic: "",
  99. video: false,
  100. share: false,
  101. path: "深圳 龙岗",
  102. sharenum: 20,
  103. commentnum: 30,
  104. goodnum: 20
  105. },
  106. // 图文
  107. {
  108. userpic: "../../static/demo/userpic/12.jpg",
  109. username: "哈哈",
  110. sex: 0, //0 男 1 女
  111. age: 25,
  112. isguanzhu: false,
  113. title: "我是标题",
  114. titlepic: "../../static/demo/datapic/13.jpg",
  115. video: false,
  116. share: false,
  117. path: "深圳 龙岗",
  118. sharenum: 20,
  119. commentnum: 30,
  120. goodnum: 20
  121. },
  122. // 视频
  123. {
  124. userpic: "../../static/demo/userpic/12.jpg",
  125. username: "哈哈",
  126. sex: 0, //0 男 1 女
  127. age: 25,
  128. isguanzhu: false,
  129. title: "我是标题",
  130. titlepic: "../../static/demo/datapic/13.jpg",
  131. video: {
  132. looknum: "20w",
  133. long: "2:47"
  134. },
  135. share: false,
  136. path: "深圳 龙岗",
  137. sharenum: 20,
  138. commentnum: 30,
  139. goodnum: 20
  140. },
  141. ]
  142. },
  143. {
  144. loadtext: "上拉加载更多",
  145. list: [
  146. // 文字
  147. {
  148. userpic: "../../static/demo/userpic/12.jpg",
  149. username: "哈哈",
  150. sex: 0, //0 男 1 女
  151. age: 25,
  152. isguanzhu: false,
  153. title: "我是标题",
  154. titlepic: "",
  155. video: false,
  156. share: false,
  157. path: "深圳 龙岗",
  158. sharenum: 20,
  159. commentnum: 30,
  160. goodnum: 20
  161. },
  162. // 图文
  163. {
  164. userpic: "../../static/demo/userpic/12.jpg",
  165. username: "哈哈",
  166. sex: 0, //0 男 1 女
  167. age: 25,
  168. isguanzhu: false,
  169. title: "我是标题",
  170. titlepic: "../../static/demo/datapic/13.jpg",
  171. video: false,
  172. share: false,
  173. path: "深圳 龙岗",
  174. sharenum: 20,
  175. commentnum: 30,
  176. goodnum: 20
  177. },
  178. // 视频
  179. {
  180. userpic: "../../static/demo/userpic/12.jpg",
  181. username: "哈哈",
  182. sex: 0, //0 男 1 女
  183. age: 25,
  184. isguanzhu: false,
  185. title: "我是标题",
  186. titlepic: "../../static/demo/datapic/13.jpg",
  187. video: {
  188. looknum: "20w",
  189. long: "2:47"
  190. },
  191. share: false,
  192. path: "深圳 龙岗",
  193. sharenum: 20,
  194. commentnum: 30,
  195. goodnum: 20
  196. },
  197. ]
  198. },
  199. ]
  200. }
  201. },
  202. computed: {
  203. },
  204. // 上拉触底事件
  205. onReachBottom() {
  206. this.loadmore();
  207. },
  208. methods: {
  209. // tabbar点击事件
  210. tabtap(index) {
  211. // console.log(index);
  212. this.tabIndex = index;
  213. },
  214. loadmore() {
  215. if (this.tablist[this.tabIndex].loadtext != "上拉加载更多") {
  216. return;
  217. }
  218. // 修改状态
  219. this.tablist[this.tabIndex].loadtext = "加载中...";
  220. // 获取数据
  221. setTimeout(() => {
  222. //获取完成
  223. let obj = {
  224. userpic: "../../static/demo/userpic/12.jpg",
  225. username: "哈哈",
  226. sex: 0, //0 男 1 女
  227. age: 25,
  228. isguanzhu: false,
  229. title: "我是标题",
  230. titlepic: "../../static/demo/datapic/13.jpg",
  231. video: false,
  232. share: false,
  233. path: "深圳 龙岗",
  234. sharenum: 20,
  235. commentnum: 30,
  236. goodnum: 20
  237. };
  238. this.tablist[this.tabIndex].list.push(obj);
  239. this.tablist[this.tabIndex].loadtext = "上拉加载更多";
  240. }, 1000);
  241. }
  242. }
  243. }
  244. </script>
  245. <style>
  246. .user-spaace-margin {
  247. margin: 15upx 0;
  248. }
  249. </style>

结束