开始

粉丝这里是加号
image.png

加号的样式
image.png
上面注释的是原来的图标。下面是新的加号图标。
image.png

image.png
图标添加颜色。
吸取颜色。
image.png

image.png
颜色没起作用。

image.png

image.png

image.png

性别,还差还一个女性

这个组件内
image.png
给女换个背景色
image.png

image.png

  1. .icon-nv{
  2. background: #FF698D!important;
  3. }

修改性别
image.png

image.png

组织数据

image.png

  1. list: [{
  2. userpic: "../../static/demo/userpic/11.jpg",
  3. username: "昵称",
  4. age: 20,
  5. sex: 0,
  6. isguanzhu: true
  7. },
  8. {
  9. userpic: "../../static/demo/userpic/11.jpg",
  10. username: "昵称",
  11. age: 21,
  12. sex: 1,
  13. isguanzhu: false
  14. }
  15. ]

block 通过v-for
image.png

image.png
三元运算符。
image.png

  1. <!-- 好友列表 -->
  2. <block v-for="(item,index) in list" :key="index">
  3. <view class="user-list u-f-ac">
  4. <image :src="item.userpic" mode="widthFix" lazy-load="true"></image>
  5. <view>
  6. <view>{{item.username}}</view>
  7. <view style="display: inline-block;">
  8. <tag-sex-age :age="item.age" :sex="item.sex"></tag-sex-age>
  9. </view>
  10. </view>
  11. <view class="icon iconfont u-f-ajc"
  12. :class="[item.isguanzhu?'icon-xuanze-yixuan':' icon-zengjia1']"></view>
  13. </view>
  14. </block>

image.png
数据的value没有给赋值
image.png

再加一条数据
image.png

  1. {
  2. userpic:"../../static/demo/userpic/11.jpg",
  3. username:"昵称",
  4. age:20,
  5. sex:0,
  6. isguanzhu:true
  7. },
  8. {
  9. userpic:"../../static/demo/userpic/11.jpg",
  10. username:"昵称",
  11. age:21,
  12. sex:1,
  13. isguanzhu:false
  14. },

image.png

组装组件

新建目录
image.png
新建vue文件
image.png
剪切到组件内
image.png

  1. <view class="user-list u-f-ac">
  2. <image :src="item.userpic" mode="widthFix" lazy-load="true"></image>
  3. <view>
  4. <view>{{item.username}}</view>
  5. <view style="display: inline-block;">
  6. <tag-sex-age :age="item.age" :sex="item.sex"></tag-sex-age>
  7. </view>
  8. </view>
  9. <view class="icon iconfont u-f-ajc"
  10. :class="[item.isguanzhu?'icon-xuanze-yixuan':' icon-zengjia1']"></view>
  11. </view>

整个的css样式
image.png

  1. <style scoped>
  2. .user-list {
  3. padding: 20upx 0;
  4. border-bottom: 1upx solid #EEEEEE;
  5. }
  6. .user-list>image {
  7. width: 100upx;
  8. height: 100upx;
  9. border-radius: 100%;
  10. margin-right: 20upx;
  11. flex-shrink: 0;
  12. }
  13. .user-list>view:first-of-type {
  14. flex: 1;
  15. /* background: #007AFF; */
  16. }
  17. .user-list>view:first-of-type>view:first {
  18. font-size: 35upx;
  19. }
  20. .user-list>view:last-of-type {
  21. width: 80upx;
  22. color: #CCCCCC;
  23. /* background: yellow; */
  24. }
  25. </style>

外部传入的属性值
image.png

  1. <script>
  2. export default{
  3. props:{
  4. item: Object,
  5. index: Number
  6. }
  7. }
  8. </script>

性别的子组件也要在user-list组件内引入
image.png

image.png

  1. import tagSexAge from '@/components/common/tag-sex-age.vue';
  2. tagSexAge

image.png

  1. import userList from '@/components/user-list/user-list.vue';
  2. userList

调用组件
image.png

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

image.png

tab切换

tab切换和首页的功能是类似的
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
复制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

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

把newsList也复制过来。
image.png
newsList里面有3个对象,每个里面都有loadtext。里面的list 就是我们下面的list 直接剪切过去。
image.png
复制3份数据
image.png
这里替换成我们封装的组件。
image.png

image.png

  1. <block v-for="(item,index1) in items.list" :key="index1">
  2. <user-list :item="item" :index="index1"></user-list>
  3. </block>

引入上拉下载组件
image.png

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

loadmore事件
image.png
加载更多的数据 换成我们当前的
image.png
复制一份过来
image.png

  1. loadmore(index){
  2. if(this.newslist[index].loadtext!="上拉加载更多"){ return; }
  3. // 修改状态
  4. this.newslist[index].loadtext="加载中...";
  5. // 获取数据
  6. setTimeout(()=> {
  7. //获取完成
  8. let obj={
  9. userpic:"../../static/demo/userpic/11.jpg",
  10. username:"昵称",
  11. age:20,
  12. sex:0,
  13. isguanzhu:true
  14. };
  15. this.newslist[index].list.push(obj);
  16. this.newslist[index].loadtext="上拉加载更多";
  17. }, 1000);
  18. // this.newslist[index].loadtext="没有更多数据了";
  19. },

引入无内容时候的组件
image.png

image.png

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

为了演示上拉加载 就多复制几份数据
image.png

右侧的图标被遮住了。
image.png

image.png

image.png

image.png
上拉加载没有显示。这是因为loadtext压根没写数据
image.png

image.png

image.png

image.png

加内边距

内边距加载组件内部。user-list组件
image.png

  1. .user-list {
  2. margin: 0 20upx;
  3. padding: 20upx 0;
  4. border-bottom: 1upx solid #EEEEEE;
  5. }

image.png

加动画效果

user-list组件内添加 动画样式
image.png

  1. <view class="user-list u-f-ac animated fadeInLeft fast">

本节代码

user-list组件

  1. <template>
  2. <view class="user-list u-f-ac animated fadeInLeft fast">
  3. <image :src="item.userpic" mode="widthFix" lazy-load="true"></image>
  4. <view>
  5. <view>{{item.username}}</view>
  6. <view style="display: inline-block;">
  7. <tag-sex-age :age="item.age" :sex="item.sex"></tag-sex-age>
  8. </view>
  9. </view>
  10. <view class="icon iconfont u-f-ajc"
  11. :class="[item.isguanzhu?'icon-xuanze-yixuan':' icon-zengjia1']"></view>
  12. </view>
  13. </template>
  14. <script>
  15. import tagSexAge from '@/components/common/tag-sex-age.vue';
  16. export default{
  17. components:{
  18. tagSexAge
  19. },
  20. props:{
  21. item: Object,
  22. index: Number
  23. }
  24. }
  25. </script>
  26. <style scoped>
  27. .user-list {
  28. margin: 0 20upx;
  29. padding: 20upx 0;
  30. border-bottom: 1upx solid #EEEEEE;
  31. }
  32. .user-list>image {
  33. width: 100upx;
  34. height: 100upx;
  35. border-radius: 100%;
  36. margin-right: 20upx;
  37. flex-shrink: 0;
  38. }
  39. .user-list>view:first-of-type {
  40. flex: 1;
  41. /* background: #007AFF; */
  42. }
  43. .user-list>view:first-of-type>view:first {
  44. font-size: 35upx;
  45. }
  46. .user-list>view:last-of-type {
  47. width: 80upx;
  48. color: #CCCCCC;
  49. /* background: yellow; */
  50. }
  51. </style>

user-list页面

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

结束