Space间距
Space 间距
设置组件之间的间距。
何时使用
避免组件紧贴在一起,拉开统一的空间。
-
适合行内元素的水平间距。
-
可以设置各种水平对齐方式。
代码演示
基本用法
相邻组件水平间距。
<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 lang="ts">import { UploadOutlined } from '@ant-design/icons-vue';import { defineComponent } from 'vue';export default defineComponent({ components: { UploadOutlined, },});</script>
垂直间距
相邻组件垂直间距。 可以设置 width: 100% 独占一行。
<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>
自定义尺寸
自定义间距大小。
<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">import { defineComponent, ref } from 'vue';export default defineComponent({ setup() { return { size: ref(8), }; },});</script>
对齐
设置对齐模式。
<template> <div class="space-align-container"> <div class="space-align-block"> <a-space align="center"> center <a-button type="primary">Primary</a-button> <span class="mock-block">Block</span> </a-space> </div> <div class="space-align-block"> <a-space align="start"> start <a-button type="primary">Primary</a-button> <span class="mock-block">Block</span> </a-space> </div> <div class="space-align-block"> <a-space align="end"> end <a-button type="primary">Primary</a-button> <span class="mock-block">Block</span> </a-space> </div> <div class="space-align-block"> <a-space align="baseline"> baseline <a-button type="primary">Primary</a-button> <span class="mock-block">Block</span> </a-space> </div> </div></template><script lang="ts">import { defineComponent } from 'vue';export default defineComponent({});</script><style scoped>.space-align-container { display: flex; align-items: flex-start; flex-wrap: wrap;}.space-align-block { margin: 8px 4px; border: 1px solid #40a9ff; padding: 4px; flex: none;}.space-align-block .mock-block { display: inline-block; padding: 32px 8px 16px; background: rgba(150, 150, 150, 0.2);}</style>
API
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| align | 对齐方式 | start | end |center |baseline | - | 1.6.5 | |---|---|---|---|---|
| direction | 间距方向 | vertical | horizontal | horizontal | 1.6.5 | |---|---|---|---|---|
| size | 间距大小 | small | middle | large | number | small | 1.6.5 | |---|---|---|---|---|
