13.Home-面板组件封装

场景说明

组件封装

1.静态模板

复制代码
<script setup>

</script>


<template>
  <div class="home-panel">
    <div class="container">
      <div class="head">
         <!-- 主标题和副标题 -->
        <h3>
          新鲜好物<small>新鲜出炉 品质靠谱</small>
        </h3>
      </div>
      <!-- 主体内容区域 -->
      <div> 主体内容 </div>
    </div>
  </div>
</template>

<style scoped lang='scss'>
.home-panel {
  background-color: #fff;

  .head {
    padding: 40px 0;
    display: flex;
    align-items: flex-end;

    h3 {
      flex: 1;
      font-size: 32px;
      font-weight: normal;
      margin-left: 6px;
      height: 35px;
      line-height: 35px;

      small {
        font-size: 16px;
        color: #999;
        margin-left: 20px;
      }
    }
  }
}
</style>

2.完整代码

复制代码
<script setup>

defineProps({
  title: {
    type: String,
    default: ''
  },
  subTitle: {
    type: String,
    default: ''
  }
})

</script>


<template>
  <div class="home-panel">
    <div class="container">
      <div class="head">
        <!-- 主标题和副标题 -->
        <h3>
          {{ title }}<small>{{ subTitle }}</small>
        </h3>
      </div>
      <!-- 主体内容区域 -->
      <slot name="main" />
    </div>
  </div>
</template>


<style scoped lang='scss'>
.home-panel {
  background-color: #fff;

  .head {
    padding: 40px 0;
    display: flex;
    align-items: flex-end;

    h3 {
      flex: 1;
      font-size: 32px;
      font-weight: normal;
      margin-left: 6px;
      height: 35px;
      line-height: 35px;

      small {
        font-size: 16px;
        color: #999;
        margin-left: 20px;
      }
    }
  }
}
</style>

3.测试一下

4.问题

父组件是谁

相关推荐
hexu_blog13 分钟前
前端vue 后端springboot如何实现图片去水印
前端·javascript·vue.js
whuhewei16 分钟前
React搜索框组件
前端·javascript·react.js
姓王者22 分钟前
Cloudflare Pages自定义依赖安装实践 | 姓王者的博客
前端
stringwu27 分钟前
Flutter 开发的 AI 三件套:壮汉、法师、实习生
前端
代码搬运媛30 分钟前
BFF 架构浅析:再也不用求后端改接口了
前端
ZC跨境爬虫32 分钟前
跟着 MDN 学 HTML day_50:(深入理解 DOM 中的 Text 节点)
前端·javascript·microsoft·ui·html·媒体
ZC跨境爬虫32 分钟前
跟着 MDN 学 HTML day_51:(深入理解 XPathEvaluator 接口)
前端·javascript·ui·html·音视频
wjykp38 分钟前
5.cypher语句组合与复杂操作
linux·前端·javascript
梦无矶39 分钟前
nrm自动设置npm镜像源
前端·npm·node.js
鲤鱼_5991 小时前
记录——前端开发IDEA需要的插件
前端