开始

image.png
和我们前面封装的公共列表很像
image.png
这里有一个天
image.png
还有这一条线。
image.png

组件components文件夹下新建目录和文件
image.png
把common-list这个组件复制的代码复制过来。
image.png
新建一个list.css作为公共的css
image.png
把common-list这个组件内的css都复制到公共的css内。
image.png

  1. .common-list {
  2. padding: 20upx;
  3. }
  4. .common-list-l {
  5. flex-shrink: 0;
  6. }
  7. .common-list-l image {
  8. width: 90upx;
  9. height: 90upx;
  10. border-radius: 100%;
  11. }
  12. .common-list-r {
  13. flex: 1;
  14. margin-left: 15upx;
  15. border-bottom: 1upx solid #EEEEEE;
  16. padding-bottom: 10upx;
  17. }
  18. .common-list-r>view:nth-child(3)>image {
  19. width: 100%;
  20. border-radius: 10upx;
  21. }
  22. .common-list-r>view:nth-child(1)>view:first-child {
  23. color: #999999;
  24. color: 30upx;
  25. }
  26. .common-list-r>view:nth-child(1)>view:last-child {
  27. background: #EEEEEEE;
  28. padding: 0 10upx;
  29. font-size: 32upx;
  30. }
  31. .common-list-r>view:nth-child(2) {
  32. font-size: 32upx;
  33. padding: 12upx 0;
  34. }
  35. .common-list-r>view:nth-child(3) {
  36. position: relative;
  37. margin-bottom: 10upx;
  38. }
  39. .common-list-play,
  40. .common-list-playinfo {
  41. position: absolute;
  42. color: #FFFFFF;
  43. }
  44. .common-list-play {
  45. font-size: 130upx;
  46. }
  47. .common-list-playinfo {
  48. right: 10upx;
  49. bottom: 10upx;
  50. background: rgba(51, 51, 51, 0.73);
  51. border-radius: 20upx;
  52. padding: 0 20upx;
  53. font-size: 26upx;
  54. }
  55. .common-list-r>view:nth-child(4)>view {
  56. color: #AAAAAA;
  57. }
  58. .common-list-r>view:nth-child(4)>view:nth-child(2)>view {
  59. margin-left: 10upx;
  60. padding-left: 5upx;
  61. font-size: 28upx;
  62. }
  63. .common-list-share {
  64. background: #EEEEEE;
  65. /* border: 1upx solid; */
  66. width: 100%;
  67. padding: 10upx;
  68. border-radius: 10upx;
  69. }
  70. .common-list-share>image {
  71. width: 200upx;
  72. height: 150upx;
  73. margin-right: 10upx;
  74. }

image.png
common-list组件内引用公共的list.css
image.png
details-info组件也引入这个css
image.png
最新的HBuilder的引用方式是下面这种。

  1. @import url('@/common/list.css');

原有页面不变。没有引起错误
image.png
details页面引入组件。
image.png

  1. <detail-info :item=""></detail-info>
  2. import detailInfo from '@/components/detail/detail-info.vue';

组件内修改,这个组件可以不要了
image.png
填充数据。复制news页面内的数据
image.png
复制到details页面
image.png

  1. detail: {
  2. userpic: "../../static/demo/userpic/12.jpg",
  3. username: "哈哈",
  4. sex: 0, //0 男 1 女
  5. age: 25,
  6. isguanzhu: false,
  7. title: "我是标题",
  8. titlepic: "../../static/demo/datapic/13.jpg",
  9. video: false,
  10. share: false,
  11. path: "深圳 龙岗",
  12. sharenum: 20,
  13. commentnum: 30,
  14. goodnum: 20
  15. }

传入组件。
image.png

这个时候会出现一些错误
image.png
错误主要是这个组件的路径问题,现在修复。
image.png

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

点击详情
image.png

图文的数据

  1. {
  2. userpic: "../../static/demo/userpic/12.jpg",
  3. username: "哈哈",
  4. sex: 0, //0 男 1 女
  5. age: 25,
  6. isguanzhu: false,
  7. title: "我是标题",
  8. titlepic: "../../static/demo/datapic/13.jpg",
  9. video: false,
  10. share: false,
  11. path: "深圳 龙岗",
  12. sharenum: 20,
  13. commentnum: 30,
  14. goodnum: 20
  15. }

最下面的一条线要求 放在最外面
image.png

  1. <style scoped>
  2. @import url('@/common/list.css');
  3. .common-list-r{
  4. border-bottom: 0;
  5. }
  6. .common-list{
  7. border-bottom: 1upx solid #EEEEEE;
  8. }
  9. </style>

让这几个单独占一行。下面加一行时间
image.png
添加一行时间
image.png

  1. <view class="common-list-r-time">26天前</view>

时间的样式
image.png
上下的边距是15 左右是0。 然后是字体颜色和大小。
image.png

  1. .common-list-r-time{
  2. padding: 15upx 0;
  3. color: #CCCCCC;
  4. font-size: 25upx;
  5. }

image.png
外面再嵌套一个view
image.png

image.png

  1. <view>
  2. <view class="u-f-ac u-f-jsb">
  3. <view class="u-f-ac">
  4. {{item.username}}
  5. <tag-sex-age :sex="item.sex" :age="item.age"></tag-sex-age>
  6. </view>
  7. <view v-show="!isguanzhu" class="icon iconfont icon-zengjia" @tap="guanzhu">关注</view>
  8. </view>
  9. <view class="common-list-r-time">26天前</view>
  10. </view>

image.png
复制公共的样式过来修改
image.png

  1. .common-list-r>view:nth-child(1)>view:first-child {
  2. color: #999999;
  3. color: 30upx;
  4. }
  5. .common-list-r>view:nth-child(1)>view:last-child {
  6. background: #EEEEEEE;
  7. padding: 0 10upx;
  8. font-size: 32upx;
  9. }

因为我们又嵌套了一层view 所以要再加上一层
image.png

  1. .common-list-r>view:nth-child(1)>view:nth-child(1)>view:first-child {
  2. color: #999999;
  3. color: 30upx;
  4. }
  5. .common-list-r>view:nth-child(1)>view:nth-child(1)>view:last-child {
  6. background: #EEEEEEE;
  7. padding: 0 10upx;
  8. font-size: 32upx;
  9. }

上面没有问题了。就差下面
image.png

image.png

  1. .common-list-r-time{
  2. padding: 15upx 0;
  3. color: #CCCCCC!important;
  4. font-size: 25upx;
  5. background: #FFFFFF;
  6. }

image.png

image.png

  1. .common-list-r-time{
  2. padding: 15upx 0;
  3. color: #CCCCCC!important;
  4. font-size: 25upx;
  5. background: #FFFFFF!important;
  6. }

image.png

图片事件

加一个属性,表示上传的时候的多张图片的效果。titlepic就表示 下面的数组的默认的第一个。
image.png

  1. morepic:["../../static/demo/datapic/13.jpg"],

图片改成循环 图片的数组
image.png

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

image.png
图片加点击事件
image.png

  1. @tap="imgdetail"

传index过去。
image.png

  1. @tap="imgdetail(index)"

image.png

image.png

image.png

  1. imgdetail(index){
  2. uni.previewImage({
  3. current:index,
  4. urls:this.item.morepic
  5. })
  6. }

image.png
点击图片后,被单独的放大了。
image.png
多加几张图片
image.png

  1. morepic:["../../static/demo/datapic/13.jpg","../../static/demo/datapic/12.jpg"],

image.png
图片竖直方向展示
image.png

  1. <view class="u-f-ajc" style="flex-direction: column;">

image.png
可以左右滑动
image.png
图片加点边距
image.png

  1. <image
  2. :src="pic"
  3. mode="widthFix"
  4. style="margin-bottom: 15upx;"
  5. lazy-load="true" @tap="imgdetail(index)">
  6. </image>

image.png
改成20upx间距
image.png

  1. style="margin-bottom: 20upx;"

image.png

视频的展示,后续对接api接口的时候再去展示。

本节代码

detail-info.vue组件

  1. <template>
  2. <view class="common-list u-f animated fadeInLeft faster">
  3. <view class="common-list-l">
  4. <image :src="item.userpic" mode="widthFix" lazy-load="true"></image>
  5. </view>
  6. <view class="common-list-r">
  7. <view>
  8. <view class="u-f-ac u-f-jsb">
  9. <view class="u-f-ac">
  10. {{item.username}}
  11. <tag-sex-age :sex="item.sex" :age="item.age"></tag-sex-age>
  12. </view>
  13. <view v-show="!isguanzhu" class="icon iconfont icon-zengjia" @tap="guanzhu">关注</view>
  14. </view>
  15. <view class="common-list-r-time">26天前</view>
  16. </view>
  17. <view class="">{{item.title}}</view>
  18. <view class="u-f-ajc" style="flex-direction: column;">
  19. <!-- 图片 -->
  20. <block v-for="(pic,index) in item.morepic" :key="index">
  21. <image
  22. :src="pic"
  23. mode="widthFix"
  24. style="margin-bottom: 20upx;"
  25. lazy-load="true" @tap="imgdetail(index)">
  26. </image>
  27. </block>
  28. <!-- 视频 -->
  29. <template v-if="item.video">
  30. <view class="common-list-play icon iconfont icon-bofang"></view>
  31. <view class="common-list-playinfo">
  32. {{item.video.looknum}} 次播放 {{item.video.long}}
  33. </view>
  34. </template>
  35. <!-- 分享 -->
  36. <view v-if="item.share" class="common-list-share u-f-ac">
  37. <image :src="item.share.titlepic" mode="widthFix" lazy-load="true">
  38. </image>
  39. <view class="">{{item.share.title}}</view>
  40. </view>
  41. </view>
  42. <view class="u-f-ajc u-f-jsb">
  43. <view class="">{{item.path}}</view>
  44. <view class="u-f-ac">
  45. <view class="icon iconfont icon-zhuanfa">
  46. {{item.sharenum}}
  47. </view>
  48. <view class="icon iconfont icon-pinglun1">
  49. {{item.commentnum}}
  50. </view>
  51. <view class="icon iconfont icon-dianzan1">
  52. {{item.goodnum}}
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import tagSexAge from '@/components/common/tag-sex-age.vue';
  61. export default {
  62. components:{
  63. tagSexAge
  64. },
  65. props:{
  66. item:Object
  67. },
  68. data() {
  69. return {
  70. isguanzhu: this.item.isguanzhu
  71. }
  72. },
  73. methods:{
  74. guanzhu(){
  75. this.isguanzhu=true;
  76. uni.showToast({
  77. title: '关注成功',
  78. });
  79. },
  80. imgdetail(index){
  81. uni.previewImage({
  82. current:index,
  83. urls:this.item.morepic
  84. })
  85. }
  86. }
  87. }
  88. </script>
  89. <style scoped>
  90. @import url('@/common/list.css');
  91. .common-list-r{
  92. border-bottom: 0;
  93. }
  94. .common-list{
  95. border-bottom: 1upx solid #EEEEEE;
  96. }
  97. .common-list-r-time{
  98. padding: 15upx 0;
  99. color: #CCCCCC!important;
  100. font-size: 25upx;
  101. background: #FFFFFF!important;
  102. }
  103. .common-list-r>view:nth-child(1)>view:nth-child(1)>view:first-child {
  104. color: #999999;
  105. color: 30upx;
  106. }
  107. .common-list-r>view:nth-child(1)>view:nth-child(1)>view:last-child {
  108. background: #EEEEEEE;
  109. padding: 0 10upx;
  110. font-size: 32upx;
  111. }
  112. </style>

detail.vue页面

  1. <template>
  2. <view>
  3. <detail-info :item="detail"></detail-info>
  4. </view>
  5. </template>
  6. <script>
  7. import detailInfo from '@/components/detail/detail-info.vue';
  8. export default {
  9. components: {
  10. detailInfo
  11. },
  12. data() {
  13. return {
  14. detail: {
  15. userpic: "../../static/demo/userpic/12.jpg",
  16. username: "哈哈",
  17. sex: 0, //0 男 1 女
  18. age: 25,
  19. isguanzhu: false,
  20. title: "我是标题",
  21. titlepic: "../../static/demo/datapic/13.jpg",
  22. morepic:["../../static/demo/datapic/13.jpg","../../static/demo/datapic/12.jpg"],
  23. video: false,
  24. share: false,
  25. path: "深圳 龙岗",
  26. sharenum: 20,
  27. commentnum: 30,
  28. goodnum: 20
  29. }
  30. }
  31. },
  32. onLoad(e) {
  33. // console.log(e.detailDate);
  34. this.initdata(JSON.parse(e.detailDate));
  35. },
  36. // 监听导航右边按钮
  37. onNavigationBarButtonTap(e) {
  38. // console.log(e);
  39. if (e.index == 0) {
  40. console.log("分享");
  41. }
  42. },
  43. methods: {
  44. // 初始化数据
  45. initdata(obj) {
  46. console.log('拿到标题:', obj);
  47. uni.setNavigationBarTitle({
  48. title: obj.title
  49. })
  50. }
  51. }
  52. }
  53. </script>
  54. <style>
  55. </style>

结束