Skip to content

Space 间距

设置组件之间的间距。

代码演示

基本用法

相邻组件水平间距。

Space
vue
<template>
  <a-space>
    Space
    <a-button type="primary">Button</a-button>
    <a-upload>
      <a-button>
        <UploadOutlined />
        Click to Upload
      </a-button>
    </a-upload>
    <a-popconfirm title="Are you sure delete this task?" ok-text="Yes" cancel-text="No">
      <a-button>Confirm</a-button>
    </a-popconfirm>
  </a-space>
</template>
<script setup>
export {};
</script>

自定义尺寸

自定义间距大小。



vue
<template>
  <div>
    <a-slider v-model:value="size" />
    <br />
    <br />
    <a-space :size="size">
      <a-button type="primary">Primary</a-button>
      <a-button>Default</a-button>
      <a-button type="dashed">Dashed</a-button>
      <a-button type="link">Link</a-button>
    </a-space>
  </div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
const size = ref(8);
</script>

间距大小

间距预设大、中、小三种大小。 通过设置 sizelarge middle 分别把间距设为大、中间距。若不设置 size,则间距为小。



vue
<template>
  <div>
    <a-radio-group v-model:value="size1">
      <a-radio value="small">Small</a-radio>
      <a-radio value="middle">Middle</a-radio>
      <a-radio value="large">Large</a-radio>
    </a-radio-group>
    <br />
    <br />
    <a-space :size="size1">
      <a-button type="primary">Primary</a-button>
      <a-button>Default</a-button>
      <a-button type="dashed">Dashed</a-button>
      <a-button type="link">Link</a-button>
    </a-space>
  </div>
</template>
<script setup>
import { ref } from 'vue';
const size = ref('small');
</script>

垂直间距

相邻组件垂直间距。 可以设置 width: 100% 独占一行。

Card

Card content

Card content

Card

Card content

Card content

vue
<template>
  <a-space direction="vertical">
    <a-card title="Card" style="width: 300px">
      <p>Card content</p>
      <p>Card content</p>
    </a-card>
    <a-card title="Card" style="width: 300px">
      <p>Card content</p>
      <p>Card content</p>
    </a-card>
  </a-space>
</template>

分隔符

相邻组件分隔符。

vue
<template>
  <a-space>
    <template #split>
      <a-divider type="vertical" />
    </template>
    <a-typography-link>Link</a-typography-link>
    <a-typography-link>Link</a-typography-link>
    <a-typography-link>Link</a-typography-link>
  </a-space>
</template>

API

Space

参数说明类型默认值
align对齐方式start | end | center | baseline-
direction间距方向vertical | horizontalhorizontal
size间距大小small | middle | large | numbersmall
split设置拆分VueNode | v-slot-
wrap是否自动换行,仅在 horizontal 时有效booleanfalse

Space.Compact

需要表单组件之间紧凑连接且合并边框时,使用 Space.Compact。支持的组件有:

  • Button
  • AutoComplete
  • Cascader
  • DatePicker
  • Input/Input.Search
  • Select
  • TimePicker
  • TreeSelect
参数说明类型默认值
block将宽度调整为父元素宽度的选项booleanfalse
direction指定排列方向vertical | horizontalhorizontal
size子组件大小large | middle |small