开始

轮播图变成动态数据

轮播图的参数 应该写在数据里面 ,循环出来。
image.png

  1. topic:{
  2. swiper:[
  3. { src:"../../static/demo/banner2.jpg" },
  4. { src:"../../static/demo/banner2.jpg" },
  5. { src:"../../static/demo/banner2.jpg" },
  6. ]
  7. }

image.png

  1. <block v-for="(item,index) in topic.swiper" :key="index">
  2. <swiper-item>
  3. <image :src="item.src" mode="widthFix" lazy-load="true"></image>
  4. </swiper-item>
  5. </block>

热门分类

上下有两条线。
image.png
分别两行,第一行左边靠边, 第二行flex布局 由6个组件组成。
image.png

开始构造

第一行
image.png
分为左右两边
image.png

  1. <view class="topic-nav">
  2. <view class="">
  3. <view class="">热门分类</view>
  4. <view class="">
  5. 更多<view class="icon iconfont icon-jinru"></view>
  6. </view>
  7. <view class=""></view>
  8. </view>
  9. </view>

flex布局和左右两边靠边
image.png

右边 flex布局,然后垂直方向居中。
image.png

  1. <view class="topic-nav">
  2. <view class="u-f-ajc u-f-jsb">
  3. <view class="">热门分类</view>
  4. <view class="u-f-ajc">
  5. 更多<view class="icon iconfont icon-jinru"></view>
  6. </view>
  7. <view class=""></view>
  8. </view>
  9. </view>

第二行放6个view组件
image.png
flex布局
image.png

写样式

image.png

  1. .topic-nav{
  2. }
  3. .topic-nav>view:first-child{
  4. }
  5. .topic-nav>view:last-child{
  6. }

上下边框,内边距
image.png

  1. .topic-nav{
  2. border-bottom: 1upx solid #EEEEEE;
  3. border-top: 1upx solid #EEEEEE;
  4. padding: 20upx;
  5. }

image.png

image.png

第二行的样式

标题和下面每个标签的距离外边距是10upx 每一个都平均分配 ,所以是flex为1
image.png

  1. .topic-nav>view:first-child{
  2. margin-bottom: 10upx;
  3. }
  4. .topic-nav>view:last-child>view{
  5. flex: 1;
  6. }

每一个都加背景色,圆角
image.png
左右两边都加上点间距
image.png
image.png
换个背景色
image.png

  1. .topic-nav>view:last-child>view{
  2. flex: 1;
  3. background: #dddddd;
  4. color: #9E9E9E;
  5. border-radius: 10upx;
  6. margin: 0 10upx;
  7. }

flex布局,并且居中
image.png

image.png

image.png

image.png

本节代码

  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" @scrolltolower="loadmore(index)" @scroll="scroll"
  9. :scroll-top="srcollTopValue" :style="{height: swiperheight+'px'}">
  10. <!-- 列表 -->
  11. <block v-for="(item,index) in guanzhu.list" :ket="index">
  12. <common-list :item="item" :index="index"></common-list>
  13. </block>
  14. <!-- 上拉加载 -->
  15. <load-more :loadtext="guanzhu.loadtext"></load-more>
  16. </scroll-view>
  17. </swiper-item>
  18. <!-- 话题 -->
  19. <swiper-item>
  20. <scroll-view scroll-y class="list">
  21. <!-- 搜索框 -->
  22. <view class="search-input">
  23. <input class="uni-input" placeholder-class="icon iconfont icon-sousuo topic-search"
  24. placeholder="搜索内容" />
  25. </view>
  26. <!-- 轮播图 -->
  27. <swiper class="topic-swiper" :indicator-dots="true" :autoplay="true" :interval="3000"
  28. :duration="1000">
  29. <block v-for="(item,index) in topic.swiper" :key="index">
  30. <swiper-item>
  31. <image :src="item.src" mode="widthFix" lazy-load="true"></image>
  32. </swiper-item>
  33. </block>
  34. </swiper>
  35. <!-- 热门分类 -->
  36. <view class="topic-nav">
  37. <view class="u-f-ajc u-f-jsb">
  38. <view class="">热门分类</view>
  39. <view class="u-f-ajc">
  40. 更多<view class="icon iconfont icon-jinru"></view>
  41. </view>
  42. </view>
  43. <view class="u-f-ajc">
  44. <view class="u-f-ajc">最新</view>
  45. <view class="u-f-ajc">游戏</view>
  46. <view class="u-f-ajc">打卡</view>
  47. <view class="u-f-ajc">情感</view>
  48. <view class="u-f-ajc">故事</view>
  49. <view class="u-f-ajc">喜爱</view>
  50. </view>
  51. </view>
  52. <!-- 最近更新 -->
  53. </scroll-view>
  54. </swiper-item>
  55. </swiper>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import commonList from '@/components/common/common-list.vue';
  61. import newsNavBar from '@/components/news/news-nav-bar.vue';
  62. import loadMore from '@/components/common/load-more.vue';
  63. export default {
  64. components: {
  65. commonList,
  66. newsNavBar,
  67. loadMore
  68. },
  69. data() {
  70. return {
  71. swiperheight: 500,
  72. srcollTopValue: 0, // 默认是0
  73. tabIndex: 1,
  74. tabBars: [{
  75. name: '关注',
  76. id: 'guanzhu'
  77. },
  78. {
  79. name: '话题',
  80. id: 'toppic'
  81. },
  82. ],
  83. guanzhu: {
  84. loadtext: "上拉加载更多",
  85. list: [
  86. // 文字
  87. {
  88. userpic: "../../static/demo/userpic/12.jpg",
  89. username: "哈哈",
  90. sex: 0, //0 男 1 女
  91. age: 25,
  92. isguanzhu: false,
  93. title: "我是标题",
  94. titlepic: "",
  95. video: false,
  96. share: false,
  97. path: "深圳 龙岗",
  98. sharenum: 20,
  99. commentnum: 30,
  100. goodnum: 20
  101. },
  102. // 图文
  103. {
  104. userpic: "../../static/demo/userpic/12.jpg",
  105. username: "哈哈",
  106. sex: 0, //0 男 1 女
  107. age: 25,
  108. isguanzhu: false,
  109. title: "我是标题",
  110. titlepic: "../../static/demo/datapic/13.jpg",
  111. video: false,
  112. share: false,
  113. path: "深圳 龙岗",
  114. sharenum: 20,
  115. commentnum: 30,
  116. goodnum: 20
  117. },
  118. // 视频
  119. {
  120. userpic: "../../static/demo/userpic/12.jpg",
  121. username: "哈哈",
  122. sex: 0, //0 男 1 女
  123. age: 25,
  124. isguanzhu: false,
  125. title: "我是标题",
  126. titlepic: "../../static/demo/datapic/13.jpg",
  127. video: {
  128. looknum: "20w",
  129. long: "2:47"
  130. },
  131. share: false,
  132. path: "深圳 龙岗",
  133. sharenum: 20,
  134. commentnum: 30,
  135. goodnum: 20
  136. },
  137. // 分享
  138. {
  139. userpic: "../../static/demo/userpic/12.jpg",
  140. username: "哈哈",
  141. sex: 0, //0 男 1 女
  142. age: 25,
  143. isguanzhu: false,
  144. title: "我是标题",
  145. titlepic: "",
  146. video: false,
  147. share: {
  148. title: "我是分享的标题",
  149. titlepic: "../../static/demo/datapic/14.jpg"
  150. },
  151. path: "深圳 龙岗",
  152. sharenum: 20,
  153. commentnum: 30,
  154. goodnum: 20
  155. },
  156. ]
  157. },
  158. topic: {
  159. swiper: [{
  160. src: "../../static/demo/banner1.jpg"
  161. },
  162. {
  163. src: "../../static/demo/banner2.jpg"
  164. },
  165. {
  166. src: "../../static/demo/banner3.jpg"
  167. },
  168. ]
  169. }
  170. }
  171. },
  172. onLoad() {
  173. uni.getSystemInfo({
  174. success: (res) => {
  175. console.log('当前window高度和窗口高度');
  176. console.log(res.windowHeight);
  177. console.log(res.screenHeight);
  178. let height = res.windowHeight - uni.upx2px(100)
  179. this.swiperheight = height;
  180. }
  181. });
  182. },
  183. methods: {
  184. scroll(e) {
  185. // console.log('scroll事件',e);
  186. this.scrollTopValue = e.detail.scrollTop;
  187. },
  188. // 点击切换
  189. changeTab(index) {
  190. console.log('父页面点击:', index);
  191. this.tabIndex = index;
  192. },
  193. // 滑动事件
  194. tabChange(e) {
  195. this.tabIndex = e.details.current
  196. },
  197. // 上拉加载
  198. loadmore() {
  199. if (this.guanzhu.loadtext != "上拉加载更多") {
  200. return;
  201. }
  202. // 修改状态
  203. this.guanzhu.loadtext = "加载中...";
  204. // 获取数据
  205. setTimeout(() => {
  206. //获取完成
  207. let obj = {
  208. userpic: "../../static/demo/userpic/12.jpg",
  209. username: "哈哈",
  210. sex: 0, //0 男 1 女
  211. age: 25,
  212. isguanzhu: false,
  213. title: "我是标题",
  214. titlepic: "../../static/demo/datapic/13.jpg",
  215. video: false,
  216. share: false,
  217. path: "深圳 龙岗",
  218. sharenum: 20,
  219. commentnum: 30,
  220. goodnum: 20
  221. };
  222. this.guanzhu.list.push(obj);
  223. this.guanzhu.loadtext = "上拉加载更多";
  224. }, 1000);
  225. // this.guanzhu.loadtext="没有更多数据了";
  226. }
  227. }
  228. }
  229. </script>
  230. <style>
  231. .search-input {
  232. /* border: 1upx solid; */
  233. padding: 20upx;
  234. }
  235. .search-input>input {
  236. /* border: 1upx solid; */
  237. background: #F4F4F4;
  238. border-radius: 10upx;
  239. }
  240. .topic-search {
  241. display: flex;
  242. justify-content: center;
  243. font-size: 27upx;
  244. }
  245. .topic-swiper {
  246. padding: 0 20upx 20upx 20upx;
  247. }
  248. .topic-swiper image {
  249. width: 100%;
  250. border-radius: 10upx;
  251. }
  252. .topic-nav{
  253. border-bottom: 1upx solid #EEEEEE;
  254. border-top: 1upx solid #EEEEEE;
  255. padding: 20upx;
  256. }
  257. .topic-nav>view:first-child{
  258. margin-bottom: 10upx;
  259. }
  260. .topic-nav>view:first-child view{
  261. color: #9E9E9E;
  262. }
  263. .topic-nav>view:first-child>view:first-child{
  264. color: #333333;
  265. font-size: 32upx;
  266. }
  267. .topic-nav>view:last-child>view{
  268. flex: 1;
  269. background: #dddddd;
  270. color: #9E9E9E;
  271. border-radius: 10upx;
  272. margin: 0 10upx;
  273. }
  274. </style>

结束