Element-UI源码——Container布局容器

Container布局容器

用于布局的容器组件,方便快速搭建页面的基本结构:

<el-container>:外层容器。当子元素中包含 <el-header><el-footer> 时,全部子元素会垂直上下排列,否则会水平左右排列。

<el-header>:顶栏容器。

<el-aside>:侧边栏容器。

<el-main>:主要区域容器。

<el-footer>:底栏容器。

<el-container> 的子元素只能是后四者,后四者的父元素也只能是 <el-container>

Container

<template>
	<!-- class 中为子元素的排列方向 -->
  <section class="el-container" :class="{ 'is-vertical': isVertical }">
    <slot></slot>
  </section>
</template>

<script>
  export default {
    name: 'ElContainer',

    componentName: 'ElContainer',

    props: {
      //排列方向
      direction: String 
    },

    computed: {
      isVertical() {
        //垂直
        if (this.direction === 'vertical') {
          return true;
        } else if (this.direction === 'horizontal') {
          //水平
          return false;
        }
        //默认插槽存在时 判断插槽vnode的tag标签是否为el-header 或 el-footer
        //存在为true 垂直 否则为false 水平
        return this.$slots && this.$slots.default
          ? this.$slots.default.some(vnode => {
            const tag = vnode.componentOptions && vnode.componentOptions.tag;
            return tag === 'el-header' || tag === 'el-footer';
          })
          : false;
      }
    }
  };
</script>

Container Attributes

参数说明类型可选值默认值
direction子元素的排列方向stringhorizontal / vertical子元素中有 el-headerel-footer 时为 vertical,否则为 horizontal

样式文件

@import "mixins/mixins";

@include b(container) {
  display: flex;
  flex-direction: row;
  flex: 1;
  flex-basis: auto;
  box-sizing: border-box;
  min-width: 0;
  
	//is-vertical判断 改变flex的方向
  @include when(vertical) {
    flex-direction: column;
  }
}

el-main el-header el-footer

这几个源码内容差不多

el-main
<template>
  <main class="el-main">
    <slot></slot>
  </main>
</template>
<script>
  export default {
    name: 'ElMain',
    componentName: 'ElMain'
  };
</script>
el-header
<template>
  <header class="el-header" :style="{ height }">
    <slot></slot>
  </header>
</template>
<script>
  export default {
    name: 'ElHeader',
    componentName: 'ElHeader',
    props: {
      height: {
        type: String,
        default: '60px'
      }
    }
  };
</script>

el-Aside
<template>
<!-- 将传入的值作为内联动态样式 如果不想设置可以设置为null 这样大小由子内容决定 下面的height同理-->
<!--<el-aside width="200px">Aside</el-aside>-->
  <aside class="el-aside" :style="{ width }">
    <slot></slot>
  </aside>
</template>
<script>
  export default {
    name: 'ElAside',
    componentName: 'ElAside',
    props: {
      width: {
        type: String,
        default: '300px'
      }
    }
  };
</script>

el-footer
<template>
  <footer class="el-footer" :style="{ height }">
    <slot></slot>
  </footer>
</template>
<script>
  export default {
    name: 'ElFooter',
    componentName: 'ElFooter',
    props: {
      height: {
        type: String,
        default: '60px'
      }
    }
  };
</script>

Header Attributes
参数说明类型可选值默认值
height顶栏高度string60px
Aside Attributes
参数说明类型可选值默认值
width侧边栏宽度string300px
Footer Attributes
参数说明类型可选值默认值
height底栏高度string60px

样式文件

el-main
@import "mixins/mixins";
@import "common/var";

@include b(main) {
  // IE11 supports the <main> element partially https://caniuse.com/#search=main
  display: block;
  flex: 1;
  flex-basis: auto;
  overflow: auto;
  box-sizing: border-box;
  padding: $--main-padding;
}

el-aside、el-main将overflow设置为auto,使内容超出容器的情况下显示滚动条而不是溢出。

  • 7
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值