Layout 布局
介绍
用于快速进行布局
基础用法
Layout 组件提供 24列栅格,通过在 Col 上添加 span 属性设置列所占的宽度百分比。 offset 属性可以设置列的偏移宽度,计算方式与 span 相同。
html
<template>
<nut-row>
<nut-col :span="24">
<div class="flex-content">span:24</div>
</nut-col>
</nut-row>
<nut-row>
<nut-col :span="12">
<div class="flex-content">span:12</div>
</nut-col>
<nut-col :span="12">
<div class="flex-content flex-content-light">span:12</div>
</nut-col>
</nut-row>
<nut-row>
<nut-col :span="8">
<div class="flex-content">span:8</div>
</nut-col>
<nut-col :span="8">
<div class="flex-content flex-content-light">span:8</div>
</nut-col>
<nut-col :span="8">
<div class="flex-content">span:8</div>
</nut-col>
</nut-row>
<nut-row>
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content flex-content-light">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
</nut-row>
</template>
<style lang="scss">
.nut-row {
overflow: hidden;
&:not(:last-child) .nut-col {
margin-bottom: 15px;
}
margin-bottom: 15px;
}
.flex-content {
line-height: 40px;
color: #fff;
text-align: center;
border-radius: 6px;
background: #ff8881;
&.flex-content-light {
background: #ffc7c4;
}
&.flex-content-height {
height: 50px;
}
}
</style>
分栏间隔
html
<template>
<nut-row :gutter="10">
<nut-col :span="8">
<div class="flex-content">span:8</div>
</nut-col>
<nut-col :span="8">
<div class="flex-content flex-content-light">span:8</div>
</nut-col>
<nut-col :span="8">
<div class="flex-content">span:8</div>
</nut-col>
</nut-row>
</template>
<style lang="scss">
.nut-row {
overflow: hidden;
&:not(:last-child) .nut-col {
margin-bottom: 15px;
}
margin-bottom: 15px;
}
.flex-content {
line-height: 40px;
color: #fff;
text-align: center;
border-radius: 6px;
background: #ff8881;
&.flex-content-light {
background: #ffc7c4;
}
&.flex-content-height {
height: 50px;
}
}
</style>
Flex布局
html
<template>
<nut-row type="flex" wrap="nowrap">
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content flex-content-light">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
</nut-row>
<nut-row type="flex" justify="center">
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content flex-content-light">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
</nut-row>
<nut-row type="flex" justify="end">
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content flex-content-light">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
</nut-row>
<nut-row type="flex" justify="space-between">
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content flex-content-light">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
</nut-row>
<nut-row type="flex" justify="space-around">
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content flex-content-light">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
</nut-row>
<nut-row type="flex" justify="space-evenly">
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content flex-content-light">span:6</div>
</nut-col>
<nut-col :span="6">
<div class="flex-content">span:6</div>
</nut-col>
</nut-row>
</template>
<style lang="scss">
.nut-row {
overflow: hidden;
&:not(:last-child) .nut-col {
margin-bottom: 15px;
}
margin-bottom: 15px;
}
.flex-content {
line-height: 40px;
color: #fff;
text-align: center;
border-radius: 6px;
background: #ff8881;
&.flex-content-light {
background: #ffc7c4;
}
&.flex-content-height {
height: 50px;
}
}
</style>
API
Row Props
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
type | 布局方式,可选值为 flex | string | - |
gutter | 列元素之间的间距(单位为 px ) | string | number | - |
justify | Flex 主轴对齐方式,可选值为 start end center space-around space-between space-evenly | string | start |
align | Flex 交叉轴对齐方式,可选值为 flex-start center flex-end | string | flex-start |
flex-wrap | Flex 是否换行,可选值为 nowrap wrap reverse | string | nowrap |
Col Props
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
span | 列元素宽度(共分为 24 份,例如设置一行3个,那么 span 值为 8) | string | number | 24 |
offset | 列元素偏移距离 | string | number | 0 |
Row Events
事件名 | 说明 | 回调参数 |
---|---|---|
click | 点击时触发 | event: MouseEvent |
Col Events
事件名 | 说明 | 回调参数 |
---|---|---|
click | 点击时触发 | event: MouseEvent |