美文网首页
Vue组件开发系列之Header组件

Vue组件开发系列之Header组件

作者: vue爱好者 | 来源:发表于2018-10-30 16:20 被阅读68次

组件源码:
https://github.com/AntJavascript/widgetUI/tree/master/Header

FireShot Capture 12 - nvx - http___localhost_8080_demo#_header.png
组件结构:
<template>
    <div class='wt-header'>
        <div class="header" :class="type">
            <div class="left">
              <!-- 显示在组件左边的内容-->
                <slot name="left"></slot>
            </div>
            <div class="title">{{title}}</div>
            <div class="right">
               <!-- 显示在组件右边的内容-->
                <slot name="right"></slot>
            </div>
        </div>
    </div>
</template>

代码分析:

props参数:

props: {
    title: { // 组件的标题
      type: String,
      default: () => {
        return '';
      }
    },
    type: { // 组件类型,(可选)主要是背景色的不同(可选值:"primary", "danger", "default")
      type: String,
      default: () => {
        return 'default';
      }
    }
  }

css代码:

.wt-header {
    .header {
        display: flex;
        justify-content: space-between;
        height: 2rem;
        line-height: 2rem;
        font-size: 0.8rem;
        .title {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        &.primary {
            background: #1BB5F1;
            color:#fff;
            border: 0;
        }
        &.danger {
            background: #ef4f4f;
            color:#fff;
            border: 0;
        }
    }
}

组件源码:
https://github.com/AntJavascript/widgetUI/tree/master/Header

相关文章

网友评论

      本文标题:Vue组件开发系列之Header组件

      本文链接:https://www.haomeiwen.com/subject/kkigtqtx.html