Skip to content

Flex 弹性布局组件

Flex 为块级元素提供间距,其本身不会添加包裹元素。适用于垂直或水平方向上的子元素布局,并提供了更多的灵活性和控制能力。

平台差异说明

APP(vue)H5微信小程序

基本使用示例

html
<!-- 全局使用 -->
<hy-flex>
    <hy-button size="small">提交</hy-button>
    <hy-button size="small" type="success">审核</hy-button>
    <hy-button size="small" type="error">删除</hy-button>
</hy-flex>

设置对齐方式

  • 通过设置justify主轴方向上的对齐方式
  • 通过设置align交叉轴方向上的对齐方式
html
 <hy-flex justify="center" align="center">
    <hy-button size="small">按钮</hy-button>
</hy-flex>

设置间隙

  • 通过设置gap控制元素之间的间距,数组第一个是横向间距,第二个是纵向间距
html
 <hy-flex :gap="10">
    <template v-for="item in 4">
        <hy-button size="small">按钮</hy-button>
    </template>
</hy-flex>

自动换行

  • 通过设置wrap自动换行
html
 <hy-flex wrap="wrap" :gap="[15, 20]">
    <template v-for="item in 10">
        <hy-button size="small">按钮</hy-button>
    </template>
</hy-flex>

API

参数说明类型默认值
verticalflex 主轴的方向是否垂直,使用 flex-direction: columnbooleanflex
wrap设置元素单行显示还是多行显示boolean-
justify设置元素在主轴方向上的对齐方式flex-start|center|flex-end|space-between|space-around|space-evenly-
align设置元素在交叉轴方向上的对齐方式flex-start|center|flex-end|stretch|baseline-
flexflex CSS 简写属性initial|none|0-
gap设置网格之间的间隙string | number | (number|string)[]0
show是否显示空状态boolean-
customStyle自定义需要用到的外部样式CSSProperties-
customClass自定义外部类名string-
10:00