Skip to content
On this page

Flex 弹性布局 ​

s-flex 是一个轻量级 flex 容器组件,用来快速设置主轴方向、换行、对齐方式、间距,以及组件自身在父级 flex 容器中的伸缩规则。

参考:Ant Design Vue Flex / MDN flex

Hidden Title ​

基础用法:<s-flex class="h-100"></s-flex>

属性事件插槽简介 ​

基础用法 ​

按钮间距(gap 默认值:0px) ​

常用属性 ​

容器尺寸 ​

图标间距(gap 默认值:0px) ​

基础写法:<s-flex gap="12"><s-icon icon="Edit" /><s-icon icon="Delete" /></s-flex>。gap 支持 small / default / large(8 / 16 / 24px)、数字和带单位的长度,默认值为 0px;裸写 gap 等价于 gap="small"。

样式简写属性(Style Props) ​

所有 sybz 组件都通过全局 mixin 自动接受 Mantine 风格的样式简写属性,无需逐个声明,直接以简写作为 prop 传入即可,例如 m(margin)、p(padding)、fs(font-size)、bg(background)、c(color)、w / h(宽高)、bd(border)、br(border-radius)等;长度类属性的数字会自动补全为 px。基础写法:<s-flex gap="small" m="12px" p="16px" bg="#f0f6ff"></s-flex>。

API ​

属性名说明类型可选值默认值
direction主轴方向,对应 flex-directionstringrow / row-reverse / column / column-reverserow
wrap是否换行;裸写或传 true 等价于 wrap,传 false 等价于 nowrapboolean / stringtrue / false / nowrap / wrap / wrap-reversenowrap
justify主轴对齐方式,对应 justify-contentstringstart / end / center / space-between / space-around / space-evenly / normalnormal
align交叉轴对齐方式,对应 align-itemsstringstart / end / center / baseline / stretch / normalnormal
gap子元素间距,对应 gap;裸写或 true 等价于 small,false 等价于 0pxboolean / string / numbertrue / false / small / default / large / 任意可被 processWidth 处理的宽度0px
flex当前 s-flex 自身在父级 flex 容器中的伸缩规则,对应 CSS flex 简写string任意合法 CSS flex 值,如 1、0 0 180px''
width容器宽度string / number任意可被 processWidth 处理的 CSS 长度-
height容器高度string / number任意可被 processWidth 处理的 CSS 长度-
component自定义根节点标签或组件string / Component原生标签名或 Vue 组件div

Gap 预设 ​

值转换结果
裸写/true8px(等价于 small)
false0px(等价于不设间距)
small8px
default16px
large24px
number交给 processWidth 处理,通常转成 px
string交给 processWidth 处理,例如 12px、1rem、50%

插槽 ​

插槽名说明
defaultflex 容器内部内容

说明 ​

  • justify="normal" 和 align="normal" 时不会输出对应 CSS 属性,由浏览器默认行为决定。
  • flex 控制的是 s-flex 自身在父级 flex 容器里的伸缩,不是控制子项。
  • component 可以传原生标签,例如 component="section",也可以传 Vue 组件对象。

思云博智私有前端组件库