element/examples/docs/zh-CN/card.md

171 lines
3.1 KiB
Markdown
Raw Normal View History

## Card 卡片
2016-09-07 10:46:20 +00:00
将信息聚合在卡片容器中展示。
2016-08-16 10:51:53 +00:00
### 基础用法
2016-08-18 09:29:11 +00:00
包含标题,内容和操作。
2016-08-16 10:51:53 +00:00
:::demo Card 组件包括`header`和`body`部分,`header`部分需要有显式具名 slot 分发,同时也是可选的。
2016-08-16 10:51:53 +00:00
```html
2016-09-07 08:24:22 +00:00
<el-card class="box-card">
<div slot="header" class="clearfix">
2017-09-14 04:14:35 +00:00
<span>卡片名称</span>
<el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button>
2016-08-16 10:51:53 +00:00
</div>
2017-04-28 06:03:42 +00:00
<div v-for="o in 4" :key="o" class="text item">
2016-08-16 10:51:53 +00:00
{{'列表内容 ' + o }}
</div>
</el-card>
<style>
.text {
font-size: 14px;
}
.item {
2017-09-14 04:14:35 +00:00
margin-bottom: 18px;
}
.clearfix:before,
.clearfix:after {
2017-09-14 04:14:35 +00:00
display: table;
content: "";
}
.clearfix:after {
2017-09-14 04:14:35 +00:00
clear: both
}
.box-card {
width: 480px;
}
</style>
2016-08-16 10:51:53 +00:00
```
:::
2016-08-16 10:51:53 +00:00
### 简单卡片
2016-08-18 09:29:11 +00:00
卡片可以只有内容区域。
2016-08-16 10:51:53 +00:00
:::demo
2016-08-16 10:51:53 +00:00
```html
2016-09-07 08:24:22 +00:00
<el-card class="box-card">
2017-04-28 06:03:42 +00:00
<div v-for="o in 4" :key="o" class="text item">
2016-08-16 10:51:53 +00:00
{{'列表内容 ' + o }}
</div>
</el-card>
<style>
.text {
font-size: 14px;
}
.item {
padding: 18px 0;
}
.box-card {
width: 480px;
}
</style>
2016-08-16 10:51:53 +00:00
```
:::
2016-08-16 10:51:53 +00:00
2016-09-06 04:47:25 +00:00
### 带图片
2016-08-18 09:29:11 +00:00
可配置定义更丰富的内容展示。
2016-08-16 10:51:53 +00:00
:::demo 配置`body-style`属性来自定义`body`部分的`style`,我们还使用了布局组件。
```html
2016-08-16 10:51:53 +00:00
<el-row>
2017-04-28 06:03:42 +00:00
<el-col :span="8" v-for="(o, index) in 2" :key="o" :offset="index > 0 ? 2 : 0">
2016-08-16 10:51:53 +00:00
<el-card :body-style="{ padding: '0px' }">
<img src="../../examples/assets/images/hamburger.png" class="image">
<div style="padding: 14px;">
<span>好吃的汉堡</span>
<div class="bottom clearfix">
2016-08-16 10:51:53 +00:00
<time class="time">{{ currentDate }}</time>
<el-button type="text" class="button">操作按钮</el-button>
2016-08-16 10:51:53 +00:00
</div>
</div>
</el-card>
</el-col>
</el-row>
<style>
.time {
font-size: 13px;
color: #999;
}
.bottom {
margin-top: 13px;
line-height: 12px;
}
.button {
padding: 0;
float: right;
}
.image {
width: 100%;
display: block;
}
.clearfix:before,
.clearfix:after {
display: table;
content: "";
}
.clearfix:after {
clear: both
}
</style>
<script>
export default {
data() {
return {
currentDate: new Date()
};
}
}
</script>
2016-08-16 10:51:53 +00:00
```
:::
2016-08-16 10:51:53 +00:00
### 卡片阴影
可对阴影的显示进行配置。
:::demo 通过`shadow`属性设置卡片阴影出现的时机:`always`、`hover`或`never`。
```html
<el-row :gutter="12">
<el-col :span="8">
<el-card shadow="always">
总是显示
</el-card>
</el-col>
<el-col :span="8">
<el-card shadow="hover">
鼠标悬浮时显示
</el-card>
</el-col>
<el-col :span="8">
<el-card shadow="never">
从不显示
</el-card>
</el-col>
</el-row>
```
:::
### Attributes
2016-08-16 10:51:53 +00:00
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---------- |-------- |---------- |------------- |-------- |
2016-09-02 05:56:47 +00:00
| header | 设置 header也可以通过 `slot#header` 传入 DOM | string| — | — |
| body-style | 设置 body 的样式| object| — | { padding: '20px' } |
| shadow | 设置阴影显示时机 | string | always / hover / never | always |