开始

image.png

image.png

  1. <!-- 搜索框 -->
  2. <!-- 轮播图 -->
  3. <!-- 热门分类 -->
  4. <!-- 最近更新 -->

为了方便后续的调试,先把这里改成1 这样默认打开的就是话题的tab
image.png
image.png
uni-input这是官方提供的input的 样式。
image.png
外层套一层view
image.png

  1. <view class="search-input">
  2. <input class="uni-input" type="text" value="" />
  3. </view>

type的默认就是text 所以我们可以不用写
image.png
value也不需要写,这里加一个占位符 placeholder
image.png

image.png

  1. <view class="search-input">
  2. <input class="uni-input" placeholder="搜索内容"/>
  3. </view>

占位符的样式
image.png

  1. <view class="search-input">
  2. <input class="uni-input" placeholder-class="topic-search" placeholder="搜索内容"/>
  3. </view>

都先加上边框
image.png

  1. .search-input{
  2. border: 1upx solid;
  3. }
  4. .search-input>input{
  5. border: 1upx solid;
  6. }

image.png

image.png
增加内边距和背景色
image.png
增加圆角
image.png

  1. .search-input{
  2. border: 1upx solid;
  3. padding: 20upx;
  4. }
  5. .search-input>input{
  6. border: 1upx solid;
  7. background: #F4F4F4;
  8. border-radius: 10upx;
  9. }

image.png
占位符居中,flex布局,并且居中
image.png

  1. .topic-search{
  2. display: flex;
  3. justify-content: center;
  4. }

这样搜索内容4个字就居中了
image.png

增加搜索的图标
image.png

image.png
复制的图标样式,放到这里
image.png

  1. icon iconfont icon-sousuo

image.png
文字大小 调的小一点
image.png

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

结束