开始

主页信息这块。
image.png
先来构建UI布局
有点内边距 ,所以需要用view包裹起来。
image.png

image.png

  1. <!-- 主页 -->
  2. <view class="user-space-userinfo">
  3. <view class="user-space-userinfo-item">
  4. <view>账号信息</view>
  5. <view>糗龄:XXXX</view>
  6. <view>糗百ID: 1231</view>
  7. </view>
  8. </view>

左右加点内边距。
image.png
上下内边距,最下面边框线。
image.png

  1. .user-space-userinfo{
  2. padding: 0 30upx;
  3. }
  4. .user-space-userinfo-item{
  5. padding: 20upx 0;
  6. border-bottom: 1upx solid #EEEEEE;
  7. }

image.png

  1. .user-space-userinfo-item>view{
  2. color: #AAAAAA;
  3. }
  4. .user-space-userinfo-item>view:first-child{
  5. color: #333333;
  6. font-size: 35upx;
  7. padding: 15upx 0;
  8. }

第一行 字体大小,字要大一些,上下边距。
image.png

image.png
复制上面代码,进行修改。
image.png

  1. <view class="user-space-userinfo-item">
  2. <view>个人信息</view>
  3. <view>星座:天秤座</view>
  4. <view>职业: IT</view>
  5. <view>故乡: 广东广州</view>
  6. <view>情感: 已婚</view>
  7. </view>

image.png

  1. <!-- 主页 -->
  2. <view class="user-space-userinfo">
  3. <view class="user-space-userinfo-item">
  4. <view>账号信息</view>
  5. <view>糗龄:150天23小时</view>
  6. <view>糗百ID: 1231</view>
  7. </view>
  8. <view class="user-space-userinfo-item">
  9. <view>个人信息</view>
  10. <view>星座:天秤座</view>
  11. <view>职业: IT</view>
  12. <view>故乡: 广东广州</view>
  13. <view>情感: 已婚</view>
  14. </view>
  15. </view>

image.png

构建data数据

糗龄是注册时间计算出来的
image.png

  1. regtime:'2019-04-11'

image.png

  1. regtime:'2019-04-11',
  2. id:1213,
  3. birthday: '1987-02-07',
  4. job: 'IT',
  5. path: '广东广州',
  6. qg: '已婚'

image.png

  1. <!-- 主页 -->
  2. <view class="user-space-userinfo">
  3. <view class="user-space-userinfo-item">
  4. <view>账号信息</view>
  5. <view>糗龄:{{userinfo.regtime}}</view>
  6. <view>糗百ID: {{userinfo.id}}</view>
  7. </view>
  8. <view class="user-space-userinfo-item">
  9. <view>个人信息</view>
  10. <view>星座:{{userinfo.birthday}}</view>
  11. <view>职业: {{userinfo.job}}</view>
  12. <view>故乡: {{userinfo.path}}</view>
  13. <view>情感: {{userinfo.qg}}</view>
  14. </view>
  15. </view>

封装好的方法 计算糗龄。记得替换成最新的time.js
image.png
使用计算属性。糗龄和星座。
image.png

  1. import t from "../../common/time.js";
  2. // 计算属性
  3. computed: {
  4. getRegAge() {
  5. return t.gettime.sumAge(this.userinfo.regtime)
  6. },
  7. getXingZuo() {
  8. return t.gettime.getHoroscope(this.userinfo.birthday)
  9. }
  10. },

image.png

  1. <view>糗龄:{{getRegAge}}</view>
  2. <view>星座:{{getXingZuo}}</view>

image.png

image.png

image.png

封装成组件

image.png

  1. <view class="user-space-userinfo">
  2. <view class="user-space-userinfo-item">
  3. <view>账号信息</view>
  4. <view>糗龄:{{getRegAge}}</view>
  5. <view>糗百ID: {{userinfo.id}}</view>
  6. </view>
  7. <view class="user-space-userinfo-item">
  8. <view>个人信息</view>
  9. <view>星座:{{getXingZuo}}</view>
  10. <view>职业: {{userinfo.job}}</view>
  11. <view>故乡: {{userinfo.path}}</view>
  12. <view>情感: {{userinfo.qg}}</view>
  13. </view>
  14. </view>

image.png

image.png

image.png

  1. <style scoped>
  2. .user-space-data {
  3. background: #FFFFFF;
  4. position: relative;
  5. z-index: 10;
  6. border-top-left-radius: 20upx;
  7. border-top-right-radius: 20upx;
  8. margin-top: -15upx;
  9. }
  10. .user-space-userinfo {
  11. padding: 0 30upx;
  12. }
  13. .user-space-userinfo-item {
  14. padding: 20upx 0;
  15. border-bottom: 1upx solid #EEEEEE;
  16. }
  17. .user-space-userinfo-item>view {
  18. color: #AAAAAA;
  19. }
  20. .user-space-userinfo-item>view:first-child {
  21. color: #333333;
  22. font-size: 35upx;
  23. padding: 15upx 0;
  24. }
  25. </style>

复制两个计算属性。
image.png

  1. getRegAge() {
  2. return t.gettime.sumAge(this.userinfo.regtime)
  3. },
  4. getXingZuo() {
  5. return t.gettime.getHoroscope(this.userinfo.birthday)
  6. }

image.png

  1. import t from "../../common/time.js";

image.png

  1. import userSpaceUserinfo from '@/components/user-space/user-space-userinfo.vue';
  2. userSpaceUserinfo

image.png

  1. <user-space-userinfo :userinfo="userinfo"></user-space-userinfo>

image.png

本节代码

user-space-userinfo组件

  1. <template>
  2. <view class="user-space-userinfo">
  3. <view class="user-space-userinfo-item">
  4. <view>账号信息</view>
  5. <view>糗龄:{{getRegAge}}</view>
  6. <view>糗百ID: {{userinfo.id}}</view>
  7. </view>
  8. <view class="user-space-userinfo-item">
  9. <view>个人信息</view>
  10. <view>星座:{{getXingZuo}}</view>
  11. <view>职业: {{userinfo.job}}</view>
  12. <view>故乡: {{userinfo.path}}</view>
  13. <view>情感: {{userinfo.qg}}</view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import t from "../../common/time.js";
  19. export default{
  20. props:{
  21. userinfo: Object
  22. },
  23. computed:{
  24. getRegAge() {
  25. return t.gettime.sumAge(this.userinfo.regtime)
  26. },
  27. getXingZuo() {
  28. return t.gettime.getHoroscope(this.userinfo.birthday)
  29. }
  30. }
  31. }
  32. </script>
  33. <style scoped>
  34. .user-space-data {
  35. background: #FFFFFF;
  36. position: relative;
  37. z-index: 10;
  38. border-top-left-radius: 20upx;
  39. border-top-right-radius: 20upx;
  40. margin-top: -15upx;
  41. }
  42. .user-space-userinfo {
  43. padding: 0 30upx;
  44. }
  45. .user-space-userinfo-item {
  46. padding: 20upx 0;
  47. border-bottom: 1upx solid #EEEEEE;
  48. }
  49. .user-space-userinfo-item>view {
  50. color: #AAAAAA;
  51. }
  52. .user-space-userinfo-item>view:first-child {
  53. color: #333333;
  54. font-size: 35upx;
  55. padding: 15upx 0;
  56. }
  57. </style>

user-spce页面

  1. <template>
  2. <view>
  3. <!-- 背景图 + 用户基本信息 -->
  4. <user-space-head :userinfo="userinfo"></user-space-head>
  5. <!-- 统计 -->
  6. <view class="user-space-data">
  7. <home-data :homedata="spacedata"></home-data>
  8. </view>
  9. <view class="height:20upx;background:F4F4F4;"></view>
  10. <!-- tabbar切换 -->
  11. <swiper-tab-head :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap" scrollStyle="border-bottom:0;"
  12. scrollItemStyle="width:33%;">
  13. </swiper-tab-head>
  14. <!-- 主页 -->
  15. <user-space-userinfo :userinfo="userinfo"></user-space-userinfo>
  16. </view>
  17. </template>
  18. <script>
  19. import userSpaceHead from '@/components/user-space/user-space-head.vue';
  20. import swiperTabHead from '@/components/index/swiper-tab-head.vue';
  21. import homeData from '@/components/home/home-data.vue';
  22. import userSpaceUserinfo from '@/components/user-space/user-space-userinfo.vue';
  23. export default {
  24. components: {
  25. userSpaceHead,
  26. homeData,
  27. swiperTabHead,
  28. userSpaceUserinfo
  29. },
  30. data() {
  31. return {
  32. tabIndex: 0,
  33. tabBars: [{
  34. name: "主页",
  35. id: "zhuye"
  36. },
  37. {
  38. name: "糗事",
  39. id: "qiushi"
  40. }, {
  41. name: "动态",
  42. id: "dongtai"
  43. },
  44. ],
  45. userinfo: {
  46. bgimg: 1,
  47. userpic: '../../static/demo/userpic/11.jpg',
  48. username: '昵称',
  49. sex: 0,
  50. age: 20,
  51. isguanzhu: false,
  52. regtime: '2019-04-11',
  53. id: 1213,
  54. birthday: '1987-02-07',
  55. job: 'IT',
  56. path: '广东广州',
  57. qg: '已婚'
  58. },
  59. spacedata: [{
  60. name: "获赞",
  61. num: '10k'
  62. },
  63. {
  64. name: "关注",
  65. num: 0
  66. },
  67. {
  68. name: "粉丝",
  69. num: 0
  70. }
  71. ]
  72. }
  73. },
  74. computed: {
  75. },
  76. methods: {
  77. // tabbar点击事件
  78. tabtap(index) {
  79. // console.log(index);
  80. this.tabIndex = index;
  81. }
  82. }
  83. }
  84. </script>
  85. <style>
  86. .user-spaace-margin {
  87. margin: 15upx 0;
  88. }
  89. </style>

结束