Space 间距
代码示例
基础用法
最简单的用法。
<template>
<chi-space>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
</chi-space>
</template>
纵向排列
添加 vertical
属性可以实现纵向排列。
<template>
<chi-space vertical>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
</chi-space>
</template>
不同大小
内置了三种大小,通过 size
设置,也可以传入数字或者数组自定义。
Default:
Large:
Custom:
Custom:
<template>
<span style="margin-inline-end: 10px">Small:</span>
<chi-space size="small" inline style="max-width: 150px">
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
</chi-space>
<br />
<br />
<span style="margin-inline-end: 10px">Default:</span>
<chi-space size="default" inline style="max-width: 160px">
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
</chi-space>
<br />
<br />
<span style="margin-inline-end: 10px">Large:</span>
<chi-space size="large" inline style="max-width: 180px">
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button></chi-space
>
<br />
<br />
<span style="margin-inline-end: 10px">Custom:</span>
<chi-space :size="[20, 16]" inline style="max-width: 180px">
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button></chi-space
>
<br />
<br />
<span style="margin-inline-end: 10px">Custom:</span>
<chi-space :size="24" inline style="max-width: 180px">
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button></chi-space
>
</template>
各种布局
通过 justify
可以设置主轴的对齐方式,还可以通过 align
设置交叉轴的对齐方式。
Start
End
Space Around
Space Between
Space Evenly
<template>
<div style="max-width: 800px; padding: 20px">
<p>Start</p>
<chi-space justify="start">
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
</chi-space>
<p>End</p>
<chi-space justify="end">
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
</chi-space>
<p>Space Around</p>
<chi-space justify="space-around">
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
</chi-space>
<p>Space Between</p>
<chi-space justify="space-between">
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
</chi-space>
<p>Space Evenly</p>
<chi-space justify="space-evenly">
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
<chi-button>按钮</chi-button>
</chi-space>
</div>
</template>
API
预设类型
ts
type SpaceAlign = 'start' | 'end' | 'center' | 'baseline' | 'stretch'
type SpaceJustify = 'start' | 'end' | 'center' | 'space-around' | 'space-between' | 'space-evenly'
type SpaceSize = 'small' | 'default' | 'large' | number | [number, number]
Linker 属性
名称 | 类型 | 说明 | 默认值 |
---|---|---|---|
align | SpaceAlign | 设置交叉轴的对齐方式 | 'stretch' |
inline | boolean | 设置是否为行内布局 | false |
justify | SpaceJustify | 设置主轴的对齐方式 | start |
no-wrap | boolean | 设置是否不换行 | false |
size | SpaceSize | 设置间距的大小 | 'default' |
vertical | boolean | 设置主轴是否纵向 | false |