Skip to content

Div 盒组件

盒组件是对基本元素 divflex 流式布局的封装。

基础用法

通过标签 NueDiv 声明一个盒组件,默认的布局方向为水平。

排列间距 gap 默认为 1rem,可以通过属性 gap 自定义。

<template>
    <nue-div>
        <nue-button icon="plus-circle">新增</nue-button>
        <nue-button icon="filter">筛选</nue-button>
        <nue-button icon="refresh">刷新</nue-button>
    </nue-div>
</template>

垂直排列

通过属性 vertical 设置布局方向为垂直,具体应用为 flex-directioncolumn

<template>
    <nue-div vertical>
        <nue-button icon="plus-circle">新增</nue-button>
        <nue-button icon="filter">筛选</nue-button>
        <nue-button icon="refresh">刷新</nue-button>
    </nue-div>
</template>

对齐方式

流式布局的对齐方式拥有主轴和副轴两个方向,具体应用到 CSS 的 justify-contentalign-items 两个属性。

通过属性 justifyalign 设置主轴和副轴的对齐方式,值类型同 CSS 属性值。

<template>
    <nue-div vertical>
        <nue-div align="center">
            <nue-button size="small">按钮</nue-button>
            <nue-button>按钮</nue-button>
        </nue-div>
        <nue-divider />
        <nue-div justify="space-between">
            <nue-button>按钮</nue-button>
            <nue-button>按钮</nue-button>
        </nue-div>
    </nue-div>
</template>

溢出控制

溢出断行

通过属性 wrap 设置是否在溢出时断行,具体应用到 CSS 的 flex-wrap,属性值类型同 CSS 属性值,默认不换行。

<template>
    <nue-div vertical>
        <nue-div wrap="wrap">
            <nue-button v-for="i in 12" :key="i">按钮</nue-button>
        </nue-div>
        <nue-divider />
        <nue-div wrap="wrap-reverse">
            <nue-button v-for="i in 12" :key="i">按钮</nue-button>
        </nue-div>
    </nue-div>
</template>

溢出隐藏或滚动

通过属性 overflow 设置溢出时的处理方式,值类型为 CSS overflow 属性值,默认值为 hidden

<template>
    <nue-div vertical>
        <nue-div overflow="auto">
            <nue-button v-for="i in 12" :key="i">按钮</nue-button>
        </nue-div>
        <nue-divider />
        <nue-div overflow="hidden">
            <nue-button v-for="i in 12" :key="i">按钮</nue-button>
        </nue-div>
        <nue-divider />
        <nue-div overflow="visible">
            <nue-button v-for="i in 12" :key="i">按钮</nue-button>
        </nue-div>
    </nue-div>
</template>

组件属性与事件

下方涵盖了 NueDiv 组件所有的可用属性与事件。

属性

属性类型默认值说明
directionstring-布局方向
verticalboolean-垂直排列
alignstring-副轴对齐方式
justifystring-主轴对齐方式
flexstring-弹性布局
wrapstring-换行方式
gapstring-间距
widthstring-宽度
heightstring-高度
dividerstring | number | boolean | object-分割线
themestring | string[]-主题样式
inlineboolean-行内元素
overflowstring-溢出处理
autoFitboolean-自动适应

Released under the MIT License.