Divider 分割线
分隔段落或一行里的几项内容。
引入
ts
import { HuiDivider } from '@nscode/handy-ui'
基础用法
默认是横向的 1px 细线,颜色是主题的边框色,上下各留 16px。
vue
<template>
<p>第一段内容</p>
<HuiDivider />
<p>第二段内容</p>
</template>
带文字
默认插槽里的内容显示在线的中间。content-position 可选 left、center(默认)、right,靠一侧时那一侧留 16px 的短线。
vue
<template>
<HuiDivider content-position="left">靠左(left)</HuiDivider>
<HuiDivider>居中(center)</HuiDivider>
<HuiDivider content-position="right">靠右(right)</HuiDivider>
</template>
插槽里可以放图标、标签这类元素,不只是文字:
vue
<template>
<HuiDivider><HuiIcon name="star" /></HuiDivider>
<HuiDivider content-position="left">
<HuiSpace size="small">
<HuiIcon name="calendar" />
<span>2026 年 11 月</span>
</HuiSpace>
</HuiDivider>
<HuiDivider content-position="right"
><HuiTag type="success" size="small">已完成</HuiTag></HuiDivider
>
</template>
线型
border-style 可选 solid(默认)、dashed、dotted,带不带文字、文字在哪个位置都可以用。
vue
<template>
<HuiDivider>实线(solid)</HuiDivider>
<HuiDivider border-style="dashed">虚线(dashed)</HuiDivider>
<HuiDivider border-style="dotted">点线(dotted)</HuiDivider>
<HuiDivider border-style="dashed" />
<HuiDivider border-style="dotted" />
<HuiDivider border-style="dashed" content-position="left">虚线靠左</HuiDivider>
<HuiDivider border-style="dotted" content-position="right">点线靠右</HuiDivider>
</template>
竖向
direction="vertical" 是竖线,用来分隔一行里的几项,左右各留 8px。
vue
<template>
<p style="margin-bottom: 12px">
编辑<HuiDivider direction="vertical" />复制<HuiDivider direction="vertical" />删除
</p>
<div style="display: flex; align-items: center; height: 40px">
<span>工具栏</span>
<HuiDivider direction="vertical" />
<span>拉伸到行高</span>
</div>
</template>
竖线同样可以用三种线型:
vue
<script setup lang="ts">
import { HuiDivider, HuiSpace } from '@nscode/handy-ui'
import type { DividerBorderStyle } from '@nscode/handy-ui'
const borderStyles: DividerBorderStyle[] = ['solid', 'dashed', 'dotted']
</script>
<template>
<HuiSpace direction="vertical" align="start">
<div v-for="item in borderStyles" :key="item">
<span class="row-label">{{ item }}</span>
<span>编辑</span>
<HuiDivider direction="vertical" :border-style="item" />
<span>复制</span>
<HuiDivider direction="vertical" :border-style="item" />
<span>删除</span>
</div>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 56px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
竖线里也可以放文字,文字上下各留 12px,上下两段线平分剩下的高度。放在有高度的 flex 容器里时,竖线拉伸到容器的高度:
vue
<template>
<div class="login">
<div class="login__item">账号密码登录</div>
<HuiDivider direction="vertical">或</HuiDivider>
<div class="login__item">扫码登录</div>
</div>
</template>
<style scoped>
.login {
display: flex;
height: 160px;
padding: var(--hui-spacing-4) 0;
box-sizing: border-box;
}
.login__item {
display: flex;
flex: 1;
align-items: center;
justify-content: center;
}
</style>
祖先变量覆盖
--hui-divider-border-style可写在组件自身或任意祖先,覆盖横向与纵向分隔线的线型。未设置时仍使用border-style属性的solid/dashed/dotted;公开变量覆盖优先,属性只决定私有默认。嵌套分隔线会继承祖先公开配置。
vue
<script setup lang="ts">
import { HuiDivider, HuiSpace } from '@nscode/handy-ui'
</script>
<template>
<HuiSpace
class="divider-variables-demo"
direction="vertical"
fill
style="--hui-divider-border-style: double"
>
<span>祖先设置 double,覆盖三种属性默认线型,横竖方向均生效。</span>
<HuiDivider border-style="solid">solid默认</HuiDivider>
<HuiDivider border-style="dashed">dashed默认</HuiDivider>
<HuiDivider border-style="dotted">dotted默认</HuiDivider>
<HuiSpace style="height: 48px"
><span>左</span><HuiDivider direction="vertical" /><span>右</span></HuiSpace
>
</HuiSpace>
</template>
Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| direction | 'horizontal' | 'vertical' | 'horizontal' | 方向 |
| contentPosition | 'left' | 'center' | 'right' | 'center' | 文字位置 |
| borderStyle | 'solid' | 'dashed' | 'dotted' | 'solid' | 线型 |
Slots
| 插槽 | 说明 |
|---|---|
| default | 显示在线中间的文字或内容 |
类型
ts
import type { DividerProps } from '@nscode/handy-ui'