ElementPlus Card 卡片

Card 卡片

将信息聚合在卡片容器中展示。

基础用法

包含标题,内容和操作。

ElementPlus Card 卡片

Card 组件包括header和body部分,header部分需要有显式具名 slot 分发,同时也是可选的。

<template>
  <el-card class="box-card">
  <template #header>
    <div class="card-header">
      <span>卡片名称</span>
      <el-button class="button" type="text">操作按钮</el-button>
    </div>
  </template>
  <div v-for="o in 4" :key="o" class="text item">{{列表内容  + o }}</div>
</el-card>
</template>

<style>
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .box-card {
    width: 480px;
  }
</style>

简单卡片

卡片可以只有内容区域。

ElementPlus Card 卡片

<template>
  <el-card class="box-card">
  <div v-for="o in 4" :key="o" class="text item">{{列表内容  + o }}</div>
</el-card>
</template>

<style>
  .text {
    font-size: 14px;
  }

  .item {
    padding: 18px 0;
  }

  .box-card {
    width: 480px;
  }
</style>

带图片

可配置定义更丰富的内容展示。

ElementPlus Card 卡片

配置body-style属性来自定义body部分的style,我们还使用了布局组件。

<template>
  <el-row>
  <el-col
    :span="8"
    v-for="(o, index) in 2"
    :key="o"
    :offset="index > 0 ? 2 : 0"
  >
    <el-card :body-style="">
      <img
        src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png" rel="external nofollow" 
        class="image"
      />
      <div style="">
        <span>好吃的汉堡</span>
        <div class="bottom">
          <time class="time">{{ currentDate }}</time>
          <el-button type="text" class="button">操作按钮</el-button>
        </div>
      </div>
    </el-card>
  </el-col>
</el-row>
</template>

<script>
  export default {
    data() {
      return {
        currentDate: new Date(),
      }
    },
  }
</script>
<style>
  .time {
    font-size: 13px;
    color: #999;
  }

  .bottom {
    margin-top: 13px;
    line-height: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .button {
    padding: 0;
    min-height: auto;
  }

  .image {
    width: 100%;
    display: block;
  }
</style>

卡片阴影

可对阴影的显示进行配置。

ElementPlus Card 卡片

通过shadow属性设置卡片阴影出现的时机:always、hover或never。

<template>
  <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>
</template>

Attributes

参数说明类型可选值默认值
header设置 header,也可以通过 slot#header 传入 DOMstring
body-style设置 body 的样式object{ padding: 20px }
shadow设置阴影显示时机stringalways / hover / neveralways

作者:andy,如若转载,请注明出处:https://www.web176.com/elementplus/19830.html

(0)
打赏 支付宝 支付宝 微信 微信
andy的头像andy
上一篇 2023年5月8日
下一篇 2023年5月8日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注