开始

动态页的,导航栏的 切换功能
image.png
功能和我们的首页功能上是差不多的
image.png
我们来复制首页上的某些代码。先复制 这整块代码
image.png
上面列表先注释
image.png

  1. <swiper class="swiper-box"
  2. :style="{height: swiperheight+'px'}"
  3. :current="tabIndex"
  4. :change="tabChange">
  5. <swiper-item v-for="(items,index) in newslist" :key="index">
  6. <scroll-view scroll-y class="list" @scrolltolower="loadmore(index)" @scroll="scroll"
  7. :style="{height: swiperheight+'px'}"
  8. :scroll-top="srcollTopValue">
  9. <template v-if="items.list.length>0">
  10. <!-- 图文列表 -->
  11. <block v-for="(item,index1) in items.list" :key="index1">
  12. <index-list :item="item" :index="index1"></index-list>
  13. </block>
  14. <!-- 上拉加载 -->
  15. <load-more :loadtext="items.loadtext"></load-more>
  16. </template>
  17. <template v-else>
  18. <no-thing></no-thing>
  19. </template>
  20. </scroll-view>
  21. </swiper-item>
  22. </swiper>

因为我们只有关注和话题 所以就不需要用到循环了。
image.png
上拉加载暂时也不需要
image.png
删除后,又新增 话题。
image.png

image.png
高度是计算的,也复制过去
image.png

  1. swiperheight:500,

onLoad复制过来
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. },

还需要一个change事件
image.png
复制过来
image.png

  1. // 滑动事件
  2. tabChange(e) {
  3. this.tabIndex = e.details.current
  4. },

可以滑动了
image.png
把列表放在关注这里。
image.png

image.png

image.png

本节代码

news.vue

  1. <template>
  2. <view>
  3. <news-nav-bar :tabBars="tabBars" :tabIndex="tabIndex" @change-tab="changeTab"></news-nav-bar>
  4. <view>
  5. <swiper class="swiper-box" :style="{height: swiperheight+'px'}" :current="tabIndex" :change="tabChange">
  6. <!-- 关注 -->
  7. <swiper-item>
  8. <scroll-view scroll-y class="list">
  9. <!-- 列表 -->
  10. <block v-for="(item,index) in list" :ket="index">
  11. <common-list :item="item" :index="index"></common-list>
  12. </block>
  13. </scroll-view>
  14. </swiper-item>
  15. <!-- 话题 -->
  16. <swiper-item>
  17. <scroll-view scroll-y class="list">
  18. 话题
  19. </scroll-view>
  20. </swiper-item>
  21. </swiper>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import commonList from '@/components/common/common-list.vue';
  27. import newsNavBar from '@/components/news/news-nav-bar.vue';
  28. export default {
  29. components: {
  30. commonList,
  31. newsNavBar
  32. },
  33. data() {
  34. return {
  35. swiperheight: 500,
  36. tabIndex: 0,
  37. tabBars: [{
  38. name: '关注',
  39. id: 'guanzhu'
  40. },
  41. {
  42. name: '话题',
  43. id: 'toppic'
  44. },
  45. ],
  46. list: [
  47. // 文字
  48. {
  49. userpic: "../../static/demo/userpic/12.jpg",
  50. username: "哈哈",
  51. sex: 0, //0 男 1 女
  52. age: 25,
  53. isguanzhu: false,
  54. title: "我是标题",
  55. titlepic: "",
  56. video: false,
  57. share: false,
  58. path: "深圳 龙岗",
  59. sharenum: 20,
  60. commentnum: 30,
  61. goodnum: 20
  62. },
  63. // 图文
  64. {
  65. userpic: "../../static/demo/userpic/12.jpg",
  66. username: "哈哈",
  67. sex: 0, //0 男 1 女
  68. age: 25,
  69. isguanzhu: false,
  70. title: "我是标题",
  71. titlepic: "../../static/demo/datapic/13.jpg",
  72. video: false,
  73. share: false,
  74. path: "深圳 龙岗",
  75. sharenum: 20,
  76. commentnum: 30,
  77. goodnum: 20
  78. },
  79. // 视频
  80. {
  81. userpic: "../../static/demo/userpic/12.jpg",
  82. username: "哈哈",
  83. sex: 0, //0 男 1 女
  84. age: 25,
  85. isguanzhu: false,
  86. title: "我是标题",
  87. titlepic: "../../static/demo/datapic/13.jpg",
  88. video: {
  89. looknum: "20w",
  90. long: "2:47"
  91. },
  92. share: false,
  93. path: "深圳 龙岗",
  94. sharenum: 20,
  95. commentnum: 30,
  96. goodnum: 20
  97. },
  98. // 分享
  99. {
  100. userpic: "../../static/demo/userpic/12.jpg",
  101. username: "哈哈",
  102. sex: 0, //0 男 1 女
  103. age: 25,
  104. isguanzhu: false,
  105. title: "我是标题",
  106. titlepic: "",
  107. video: false,
  108. share: {
  109. title: "我是分享的标题",
  110. titlepic: "../../static/demo/datapic/14.jpg"
  111. },
  112. path: "深圳 龙岗",
  113. sharenum: 20,
  114. commentnum: 30,
  115. goodnum: 20
  116. },
  117. ]
  118. }
  119. },
  120. onLoad() {
  121. uni.getSystemInfo({
  122. success: (res) => {
  123. console.log('当前window高度和窗口高度');
  124. console.log(res.windowHeight);
  125. console.log(res.screenHeight);
  126. let height = res.windowHeight - uni.upx2px(100)
  127. this.swiperheight = height;
  128. }
  129. });
  130. },
  131. methods: {
  132. // 点击切换
  133. changeTab(index) {
  134. console.log('父页面点击:', index);
  135. this.tabIndex = index;
  136. },
  137. // 滑动事件
  138. tabChange(e) {
  139. this.tabIndex = e.details.current
  140. },
  141. }
  142. }
  143. </script>
  144. <style>
  145. </style>

结束