Space 间距
设置组件之间的间距。
何时使用
避免组件紧贴在一起,拉开统一的空间。
基本用法
相邻组件水平间距。
<template>
<a-space>
Space
<a-button type="primary">Button</a-button>
<a-upload>
<a-button> <a-icon type="upload" /> 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>
export default {};
</script>
间距大小
间距预设大、中、小三种大小。
通过设置 size
为 large
middle
分别把间距设为大、中间距。若不设置 size
,则间距为小。
<template>
<div>
<a-radio-group v-model="size">
<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="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>
export default {
data() {
return {
size: 'small',
};
},
};
</script>
自定义尺寸
自定义间距大小。
<template>
<div>
<a-slider v-model="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>
export default {
data() {
return {
size: 8,
};
},
};
</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>
<script>
export default {};
</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>
export default {};
</script>
<style scoped>
.space-align-container {
display: flex;
align-item: 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 |