vue 公共組件封裝(slot 插槽使用)


使用場景:

    

 

 

公共組件:

<template>
  <div class="title-box">
    <div class="title">
      <span>{{title}}</span>
      <slot name="right"></slot>
    </div>
    <span class="square"></span>
  </div>
</template>
<style>
</style>
<script>
export default {
  name: 'cardTitle',
  props: {
    title: {
      default: '',
    },
  },
  data() {
    return {}
  },
}
</script>
<style scoped lang="scss">
@import '@/styles/colorVariables.scss';
.title-box {
  position: relative;
  height: 0.5rem;
  line-height: 0.5rem;
  border-bottom: 1px solid $white_6;
  .title {
    font-size: 0.16rem;
    display: flex;
    justify-content: space-between;
  }
  .square {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 16px;
    height: 4px;
    background: $white;
  }
  .legend {
    ul li {
      font-size: 0.12rem;
      color: $white_5;
      i {
        float: left;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: $yellow1;
        margin: calc((0.5rem - 8px) / 2) 10px 0 0;
      }
    }
  }
}
</style>

 

 場景1使用:

<cardTitle title="機電設備統計"></cardTitle>

 

 

 

 場景2使用:

<cardTitle title="機電設備統計">
          <div slot="right" class="legend">
            <ul>
              <li>
                <i></i>
                建築總用電(kWh)
              </li>
            </ul>
          </div>
</cardTitle>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM