Skip to content

Space

通过这个组件来给组件之间提供统一的间距。

基础用法

最基础的用法,通过这个组件来给组件之间提供统一的间距。

vue
<template>
  <v-space wrap>
    <v-button v-for="key in 4" :key="key" theme="primary">
      Button
    </v-button>
  </v-space>
</template>

控制间距的大小

通过调整 size 的值来控制间距的大小

vue
<template>
  <v-space direction="column">
    <v-space wrap size="small">
      <v-button v-for="key in 4" :key="key" theme="primary">
        Button
      </v-button>
    </v-space>
    <v-space wrap size="medium">
      <v-button v-for="key in 4" :key="key" theme="primary">
        Button
      </v-button>
    </v-space>
    <v-space wrap size="large">
      <v-button v-for="key in 4" :key="key" theme="primary">
        Button
      </v-button>
    </v-space>
    <v-space wrap size="4rem">
      <v-button v-for="key in 4" :key="key" theme="primary">
        Button
      </v-button>
    </v-space>
  </v-space>
</template>

排列方向

垂直布局, 使用 direction 来控制布局的方式, 背后实际上是利用了 flex-direction 来控制.

vue
<template>
  <v-space direction="column">
    <v-button v-for="key in 4" :key="key" theme="primary">
      Button
    </v-button>
  </v-space>
</template>

自动换行

通过wrap控制设置自动换行

vue
<template>
  <v-space wrap>
    <v-button v-for="key in 30" :key="key" theme="primary">
      Button
    </v-button>
  </v-space>
</template>

对齐方式

通过align-items控制子节点对齐方式

stretch

center

start

end

normal

vue
<script setup lang="ts">
const alignItems = ['stretch', 'center', 'start', 'end', 'normal'];
</script>

<template>
  <template v-for="align in alignItems" :key="align">
    <v-space :align-items="align">
      <v-button v-for="key in 4" :key="key" theme="primary">
        Button
      </v-button>
      <div :style="{ height: '60px', border: '1px solid red', background: 'gray' }">
        {{ align }}
      </div>
    </v-space>
    <hr>
  </template>
</template>

充满整行

通过fill控制子节点充满整行

vue
<template>
  <v-space fill>
    <v-button v-for="key in 4" :key="key" theme="primary">
      Button
    </v-button>
  </v-space>
</template>

API

space 属性

属性名说明类型默认值
size间距大小string | enummedium
align-items对齐方式enumnormal
direction排列方向enumrow
wrap是否自动换行booleanfalse
fill是否充满整行booleanfalse

space 插槽

插槽名描述
default默认插槽

根据 ISC 许可证发布.