开始

把整个代码封装到一个组件
image.png
数据统一放到一起
image.png

image.png

image.png

  1. topicInfo: {
  2. titlepic: "../../static/demo/topicpic/13.jpeg",
  3. title: "忆往事,敬余生",
  4. desc: "我是描述",
  5. totalnum: 1000,
  6. todaynum: 1000,
  7. }

image.png

image.png

  1. <template>
  2. <view>
  3. <view class="topic-bg">
  4. <image :src="topicInfo.titlepic" mode="widthFix" lazy-load="true"></image>
  5. </view>
  6. <!-- 话题信息 -->
  7. <view class="topic-info">
  8. <view class="topic-info-t u-f-ac">
  9. <image :src="topicInfo.titlepic" mode="widthFix" lazy-load="true"></image>
  10. <view class="">#{{topicInfo.title}}#</view>
  11. </view>
  12. <view class="topic-info-c u-f-ac">
  13. <view class="">动态 {{topicInfo.totalnum}}</view>
  14. <view class="">今日 {{topicInfo.todaynum}}</view>
  15. </view>
  16. <view class="topic-info-b">{{topicInfo.desc}}</view>
  17. </view>
  18. </view>
  19. </template>

封装组件

image.png

最外层,嵌套一个view。里面放复制过来的代码。
image.png

image.png

  1. <view class="">
  2. <view class="topic-bg">
  3. <image :src="topicInfo.titlepic" mode="widthFix" lazy-load="true"></image>
  4. </view>
  5. <!-- 话题信息 -->
  6. <view class="topic-info">
  7. <view class="topic-info-t u-f-ac">
  8. <image :src="topicInfo.titlepic" mode="widthFix" lazy-load="true"></image>
  9. <view class="">#{{topicInfo.title}}#</view>
  10. </view>
  11. <view class="topic-info-c u-f-ac">
  12. <view class="">动态 {{topicInfo.totalnum}}</view>
  13. <view class="">今日 {{topicInfo.todaynum}}</view>
  14. </view>
  15. <view class="topic-info-b">{{topicInfo.desc}}</view>
  16. </view>
  17. </view>

css复制过来
image.png

image.png

  1. <style scoped>
  2. .topic-bg {
  3. width: 100%;
  4. height: 300upx;
  5. position: relative;
  6. overflow: hidden;
  7. }
  8. .topic-bg>image {
  9. width: 100%;
  10. position: absolute;
  11. filter: blur(10px);
  12. }
  13. .topic-info {
  14. padding: 0 25upx;
  15. }
  16. .topic-info-t {
  17. position: relative;
  18. }
  19. .topic-info-t>image {
  20. width: 150upx;
  21. height: 150upx;
  22. border-radius: 20upx;
  23. position: absolute;
  24. top: -75upx;
  25. }
  26. .topic-info-t>view {
  27. font-size: 35upx;
  28. margin-left: 170upx;
  29. flex: 1;
  30. }
  31. .topic-info-c {
  32. padding: 40upx 0 15upx 0;
  33. }
  34. .topic-info-c view {
  35. color: #CDCDCD;
  36. }
  37. .topic-info-b {
  38. color: #A3A3A3;
  39. font-size: 32upx;
  40. padding-bottom: 10upx;
  41. }
  42. </style>

image.png

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

image.png

  1. <view class="">
  2. <view class="topic-bg">
  3. <image :src="item.titlepic" mode="widthFix" lazy-load="true"></image>
  4. </view>
  5. <!-- 话题信息 -->
  6. <view class="topic-info">
  7. <view class="topic-info-t u-f-ac">
  8. <image :src="item.titlepic" mode="widthFix" lazy-load="true"></image>
  9. <view class="">#{{item.title}}#</view>
  10. </view>
  11. <view class="topic-info-c u-f-ac">
  12. <view class="">动态 {{item.totalnum}}</view>
  13. <view class="">今日 {{item.todaynum}}</view>
  14. </view>
  15. <view class="topic-info-b">{{item.desc}}</view>
  16. </view>
  17. </view>

组件引用

image.png

  1. <topic-info :item="topicInfo"></topic-info>
  2. import topicInfo from '@/components/topic/topic-info.vue';
  3. comments:{
  4. topicInfo
  5. },

image.png

本节代码

topic-info组件

  1. <template>
  2. <view class="">
  3. <view class="topic-bg">
  4. <image :src="item.titlepic" mode="widthFix" lazy-load="true"></image>
  5. </view>
  6. <!-- 话题信息 -->
  7. <view class="topic-info">
  8. <view class="topic-info-t u-f-ac">
  9. <image :src="item.titlepic" mode="widthFix" lazy-load="true"></image>
  10. <view class="">#{{item.title}}#</view>
  11. </view>
  12. <view class="topic-info-c u-f-ac">
  13. <view class="">动态 {{item.totalnum}}</view>
  14. <view class="">今日 {{item.todaynum}}</view>
  15. </view>
  16. <view class="topic-info-b">{{item.desc}}</view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. props:{
  23. item: Object
  24. }
  25. }
  26. </script>
  27. <style scoped>
  28. .topic-bg {
  29. width: 100%;
  30. height: 300upx;
  31. position: relative;
  32. overflow: hidden;
  33. }
  34. .topic-bg>image {
  35. width: 100%;
  36. position: absolute;
  37. filter: blur(10px);
  38. }
  39. .topic-info {
  40. padding: 0 25upx;
  41. }
  42. .topic-info-t {
  43. position: relative;
  44. }
  45. .topic-info-t>image {
  46. width: 150upx;
  47. height: 150upx;
  48. border-radius: 20upx;
  49. position: absolute;
  50. top: -75upx;
  51. }
  52. .topic-info-t>view {
  53. font-size: 35upx;
  54. margin-left: 170upx;
  55. flex: 1;
  56. }
  57. .topic-info-c {
  58. padding: 40upx 0 15upx 0;
  59. }
  60. .topic-info-c view {
  61. color: #CDCDCD;
  62. }
  63. .topic-info-b {
  64. color: #A3A3A3;
  65. font-size: 32upx;
  66. padding-bottom: 10upx;
  67. }
  68. </style>

topic-detail.vue页面

  1. <template>
  2. <view>
  3. <topic-info :item="topicInfo"></topic-info>
  4. </view>
  5. </template>
  6. <script>
  7. import topicInfo from '@/components/topic/topic-info.vue';
  8. export default {
  9. components:{
  10. topicInfo
  11. },
  12. data() {
  13. return {
  14. topicInfo: {
  15. titlepic: "../../static/demo/topicpic/13.jpeg",
  16. title: "忆往事,敬余生",
  17. desc: "我是描述",
  18. totalnum: 1000,
  19. todaynum: 1000,
  20. }
  21. }
  22. },
  23. methods: {
  24. }
  25. }
  26. </script>
  27. <style>
  28. </style>

结束