开始

看起来和首页非常的类似
image.png
创建页面。
image.png
配置参数
页面的标题
image.png

  1. "navigationBarTitleText": "话题分类",

app上关掉回弹的效果
image.png

  1. "app-plus": {
  2. "bounce": "none"
  3. }

我们直接复制首页的代码
image.png

image.png
注册组件
image.png
首页整段复制过来。
image.png

  1. <view>
  2. <swiper-tab-head
  3. :tabBars="tabBars"
  4. :tabIndex="tabIndex"
  5. @tabtap="tabtap">
  6. </swiper-tab-head>
  7. </view>

复制数据
image.png

  1. tabIndex: 0,
  2. tabBars: [{
  3. name: "关注",
  4. id: "guanzhu"
  5. },
  6. {
  7. name: "推荐",
  8. id: "tuijian"
  9. },
  10. {
  11. name: "体育",
  12. id: "tiyu"
  13. },
  14. {
  15. name: "热点",
  16. id: "redian"
  17. },
  18. {
  19. name: "财经",
  20. id: "caijing"
  21. },
  22. {
  23. name: "娱乐",
  24. id: "yule"
  25. },
  26. ],

image.png
复制事件
image.png

  1. tabtap(index){
  2. console.log(index);
  3. this.tabIndex=index;
  4. },

再复制这整个一块
image.png

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

image.png
没有数据不显示的组件也复制过来。
image.png

  1. import noThing from '@/components/common/no-thing.vue';

image.png

image.png
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. },

数据结构也是差不多的 ,复制过来。
image.png
复制过来后,list数据不用。和首页是不一样的
image.png
list都先设置为空了
image.png

  1. newslist: [{
  2. loadtext:'上拉加载更多',
  3. list: [
  4. ]
  5. },
  6. {
  7. loadtext:'上拉加载更多',
  8. list: [
  9. ]
  10. },
  11. {
  12. loadtext:'上拉加载更多',
  13. list: []
  14. },
  15. {
  16. loadtext:'上拉加载更多',
  17. list: []
  18. },
  19. {
  20. loadtext:'上拉加载更多',
  21. list: []
  22. },
  23. {
  24. loadtext:'上拉加载更多',
  25. list: []
  26. }
  27. ]

复制滑动事件
image.png

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

上拉加载也复制
image.png

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

注册组件
image.png
上拉加载方法复制过来
image.png

  1. loadmore(index) {
  2. console.log('触底事件');
  3. // this.newslist[index].loadtext="上拉加载更多";
  4. if(this.newslist[index].loadtext!='上拉加载更多'){return;}
  5. console.log('加载更多数据....');
  6. this.newslist[index].loadtext="加载中...";
  7. setTimeout(() => {
  8. let obj={
  9. userpic: "../../static/demo/userpic/12.jpg",
  10. username: "昵称",
  11. isguanzhu: false,
  12. title: "我是标题",
  13. type: "img", // img:图文,video:视频
  14. titlepic: "../../static/demo/datapic/11.jpg",
  15. infonum: {
  16. index: 0, //0:没有操作,1:顶,2:踩;
  17. dingnum: 11,
  18. cainum: 11,
  19. },
  20. commentnum: 10,
  21. sharenum: 10,
  22. };
  23. this.newslist[index].list.push(obj);
  24. this.newslist[index].loadtext="上拉加载更多";
  25. },1000);
  26. // this.newslist[index].loadtext="没有更多数据了";
  27. }

改本组件内

image.png

news页面引入这个话题列表
image.png

  1. import topicList from '@/components/news/topic-list.vue';
  2. topicList

image.png
组件使用 ,复制过来就行
image.png

  1. <topic-list :item="item" :index="index"></topic-list>

改成index1
image.png

  1. <topic-list :item="item" :index="index1"></topic-list>

list数据初始化。news页面下的topic的
image.png
topic下的list
image.png
粘贴到这里
image.png

  1. list: [{
  2. titlepic: "../../static/demo/topicpic/13.jpeg",
  3. title: "话题名称",
  4. desc: "我是话题描述",
  5. totalnum: 50,
  6. todaynum: 10
  7. },
  8. {
  9. titlepic: "../../static/demo/topicpic/13.jpeg",
  10. title: "话题名称",
  11. desc: "我是话题描述",
  12. totalnum: 50,
  13. todaynum: 10
  14. },
  15. {
  16. titlepic: "../../static/demo/topicpic/13.jpeg",
  17. title: "话题名称",
  18. desc: "我是话题描述",
  19. totalnum: 50,
  20. todaynum: 10
  21. },
  22. {
  23. titlepic: "../../static/demo/topicpic/13.jpeg",
  24. title: "话题名称",
  25. desc: "我是话题描述",
  26. totalnum: 50,
  27. todaynum: 10
  28. },
  29. {
  30. titlepic: "../../static/demo/topicpic/13.jpeg",
  31. title: "话题名称",
  32. desc: "我是话题描述",
  33. totalnum: 50,
  34. todaynum: 10
  35. },
  36. {
  37. titlepic: "../../static/demo/topicpic/13.jpeg",
  38. title: "话题名称",
  39. desc: "我是话题描述",
  40. totalnum: 50,
  41. todaynum: 10
  42. }
  43. ]

入口事件

热门分类的入口在这里
image.png
top-nav这个组件内,更多增加点击事件
image.png

image.png

  1. methods:{
  2. openTopicNav(){
  3. uni.navigateTo({
  4. url:'/pages/topic-nav/topic-nav'
  5. })
  6. }
  7. }

image.png
和左边的间距没有
image.png

优化样式

外层再嵌套一个view
image.png

  1. <view class="topic-view">

增加内边距。上下为0 左右为20
image.png

  1. .topic-view{
  2. padding: 0 20upx;
  3. }

加载更多的数据,替换成我们本页面数据的格式的数据
image.png

image.png
image.png

image.png

image.png

注意事项!!!!!

复制首页的代码的时候,还需要把scroll方法也复制过来。
image.png

  1. scroll(e){
  2. // console.log(e);
  3. this.srcollTopValue=e.detail.scrollTop;
  4. },

本节代码

组件topic-nav

主要是openTopicNav的点击事件

  1. <view class="u-f-ajc">
  2. 更多<view class="icon iconfont icon-jinru" @tap="openTopicNav"></view>
  3. </view>
  4. methods:{
  5. openTopicNav(){
  6. uni.navigateTo({
  7. url:'/pages/topic-nav/topic-nav'
  8. })
  9. }
  10. }

topic-nav.vue页面

  1. <template>
  2. <view>
  3. <swiper-tab-head :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap">
  4. </swiper-tab-head>
  5. <view>
  6. <swiper class="swiper-box" :style="{height: swiperheight+'px'}" :current="tabIndex" :change="tabChange">
  7. <swiper-item v-for="(items,index) in newslist" :key="index">
  8. <scroll-view scroll-y class="list" @scrolltolower="loadmore(index)" @scroll="scroll"
  9. :style="{height: swiperheight+'px'}" :scroll-top="srcollTopValue">
  10. <template v-if="items.list.length>0">
  11. <!-- 图文列表 -->
  12. <view class="topic-view">
  13. <block v-for="(item,index1) in items.list" :key="index1">
  14. <topic-list :item="item" :index="index1"></topic-list>
  15. </block>
  16. </view>
  17. <!-- 上拉加载 -->
  18. <load-more :loadtext="items.loadtext"></load-more>
  19. </template>
  20. <template v-else>
  21. <no-thing></no-thing>
  22. </template>
  23. </scroll-view>
  24. </swiper-item>
  25. </swiper>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import swiperTabHead from '@/components/index/swiper-tab-head.vue';
  31. import noThing from '@/components/common/no-thing.vue';
  32. import loadMore from '@/components/common/load-more.vue';
  33. import topicList from '@/components/news/topic-list.vue';
  34. export default {
  35. components: {
  36. swiperTabHead,
  37. noThing,
  38. loadMore,
  39. topicList
  40. },
  41. data() {
  42. return {
  43. swiperheight: 500,
  44. srcollTopValue: 0, // 默认是0
  45. tabIndex: 0,
  46. tabBars: [{
  47. name: "关注",
  48. id: "guanzhu"
  49. },
  50. {
  51. name: "推荐",
  52. id: "tuijian"
  53. },
  54. {
  55. name: "体育",
  56. id: "tiyu"
  57. },
  58. {
  59. name: "热点",
  60. id: "redian"
  61. },
  62. {
  63. name: "财经",
  64. id: "caijing"
  65. },
  66. {
  67. name: "娱乐",
  68. id: "yule"
  69. },
  70. ],
  71. newslist: [{
  72. loadtext: '上拉加载更多',
  73. list: [{
  74. titlepic: "../../static/demo/topicpic/13.jpeg",
  75. title: "话题名称",
  76. desc: "我是话题描述",
  77. totalnum: 50,
  78. todaynum: 10
  79. },
  80. {
  81. titlepic: "../../static/demo/topicpic/13.jpeg",
  82. title: "话题名称",
  83. desc: "我是话题描述",
  84. totalnum: 50,
  85. todaynum: 10
  86. },
  87. {
  88. titlepic: "../../static/demo/topicpic/13.jpeg",
  89. title: "话题名称",
  90. desc: "我是话题描述",
  91. totalnum: 50,
  92. todaynum: 10
  93. },
  94. {
  95. titlepic: "../../static/demo/topicpic/13.jpeg",
  96. title: "话题名称",
  97. desc: "我是话题描述",
  98. totalnum: 50,
  99. todaynum: 10
  100. },
  101. {
  102. titlepic: "../../static/demo/topicpic/13.jpeg",
  103. title: "话题名称",
  104. desc: "我是话题描述",
  105. totalnum: 50,
  106. todaynum: 10
  107. },
  108. {
  109. titlepic: "../../static/demo/topicpic/13.jpeg",
  110. title: "话题名称",
  111. desc: "我是话题描述",
  112. totalnum: 50,
  113. todaynum: 10
  114. }
  115. ]
  116. },
  117. {
  118. loadtext: '上拉加载更多',
  119. list: [{
  120. titlepic: "../../static/demo/topicpic/13.jpeg",
  121. title: "话题名称",
  122. desc: "我是话题描述",
  123. totalnum: 50,
  124. todaynum: 10
  125. },
  126. {
  127. titlepic: "../../static/demo/topicpic/13.jpeg",
  128. title: "话题名称",
  129. desc: "我是话题描述",
  130. totalnum: 50,
  131. todaynum: 10
  132. },
  133. {
  134. titlepic: "../../static/demo/topicpic/13.jpeg",
  135. title: "话题名称",
  136. desc: "我是话题描述",
  137. totalnum: 50,
  138. todaynum: 10
  139. },
  140. {
  141. titlepic: "../../static/demo/topicpic/13.jpeg",
  142. title: "话题名称",
  143. desc: "我是话题描述",
  144. totalnum: 50,
  145. todaynum: 10
  146. },
  147. {
  148. titlepic: "../../static/demo/topicpic/13.jpeg",
  149. title: "话题名称",
  150. desc: "我是话题描述",
  151. totalnum: 50,
  152. todaynum: 10
  153. },
  154. {
  155. titlepic: "../../static/demo/topicpic/13.jpeg",
  156. title: "话题名称",
  157. desc: "我是话题描述",
  158. totalnum: 50,
  159. todaynum: 10
  160. }
  161. ]
  162. },
  163. {
  164. loadtext: '上拉加载更多',
  165. list: []
  166. },
  167. {
  168. loadtext: '上拉加载更多',
  169. list: []
  170. },
  171. {
  172. loadtext: '上拉加载更多',
  173. list: []
  174. },
  175. {
  176. loadtext: '上拉加载更多',
  177. list: []
  178. }
  179. ]
  180. }
  181. },
  182. onLoad() {
  183. uni.getSystemInfo({
  184. success: (res) => {
  185. console.log('当前window高度和窗口高度');
  186. console.log(res.windowHeight);
  187. console.log(res.screenHeight);
  188. let height = res.windowHeight - uni.upx2px(100)
  189. this.swiperheight = height;
  190. }
  191. });
  192. },
  193. methods: {
  194. scroll(e){
  195. // console.log(e);
  196. this.srcollTopValue=e.detail.scrollTop;
  197. },
  198. tabtap(index) {
  199. console.log(index);
  200. this.tabIndex = index;
  201. },
  202. // 滑动事件
  203. tabChange(e) {
  204. this.tabIndex = e.details.current
  205. },
  206. loadmore(index) {
  207. console.log('触底事件');
  208. // this.newslist[index].loadtext="上拉加载更多";
  209. if (this.newslist[index].loadtext != '上拉加载更多') {
  210. return;
  211. }
  212. console.log('加载更多数据....');
  213. this.newslist[index].loadtext = "加载中...";
  214. setTimeout(() => {
  215. let obj = {
  216. titlepic: "../../static/demo/topicpic/13.jpeg",
  217. title: "话题名称",
  218. desc: "我是话题描述",
  219. totalnum: 50,
  220. todaynum: 10
  221. };
  222. this.newslist[index].list.push(obj);
  223. this.newslist[index].loadtext = "上拉加载更多";
  224. }, 1000);
  225. // this.newslist[index].loadtext="没有更多数据了";
  226. }
  227. }
  228. }
  229. </script>
  230. <style>
  231. .topic-view {
  232. padding: 0 20upx;
  233. }
  234. </style>

结束