element-card用法总结

博客针对利用el-card实现通知栏功能总结细节问题。一是可按需修改el-card__header样式,默认无背景色;二是列表项相关,通知栏宜用有序列表,要设置恰当行间距和首行缩进,内容过多时需自动换行,且列表项循环应放在单独div标签下。
大神请移步,菜鸟可以参考一下。

在项目中,利用el-card实现了一个类似通知栏的功能,顺便总结了一些细节问题。老规矩,先上代码:

	<el-card>
        <div slot="header">
          <span>用户须知</span>
          <el-button style="float: right" type="warning" @click="editShow(infos)" size="mini" v-if="user.privilege===10">修改</el-button>
          <el-button style="float: right;margin-right: 20px" type="primary" @click="addVisible = true" size="mini" v-if="user.privilege===10">添加</el-button>
        </div>
        <div style="margin-right: 15px; word-break: break-all">
          <ol type="1">
            <div v-for="info in infos" :key="info" class="paragraph_indent">
              <li>{{info}}</li>
            </div>
          </ol>
        </div>
      </el-card>

1、修改el-card__header 样式

.el-card__header {
    background-color: yellowgreen;
  } 

默认情况下,el-card__header没有背景颜色,用户可以根据需要进行设置

2、列表项相关

作为一个通知栏,最好能够是一个有序的列表,这样比较直观,同时,每一个单项直接需要设置恰当的行间距,首行空几个像素等。当一行的内容过多时,注意换行,

设置自动换行

 <div style="margin-right: 15px; word-break: break-all">
 省略内容。。。
 </div>

有序列表

	<ol type="1">
       <div v-for="info in infos" :key="info" class="paragraph_indent">
          <li>{{info}}</li>
        </div>
    </ol>

注意,列表项的循环放在一个单独的div的标签之下,v-for语句不要放在ol标签属性中,如果是无序列表,效果实现是相同的,但是如果是有序列表,生成的序号是相同的。

.paragraph_indent {
    text-indent: 20px;
    margin-top: 10px;
  }

上面样式主要是控制列表项的行间距及首行缩进

### 使用 Element-UI 的 el-card 组件 在 Vue 2 中使用 `el-card` 组件相对简单,主要通过引入 Element-UI 并注册组件来实现。以下是详细的说明和示例。 #### 安装并引入 Element-UI 为了能够在项目中使用 `el-card` 组件,首先需要安装 Element-UI: ```bash npm install element-ui --save ``` 接着,在项目的入口文件(通常是 main.js 或者类似的初始化文件)中全局引入 Element-UI 和样式: ```javascript import Vue from 'vue'; import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(ElementUI); ``` #### 基本用法 下面是一个基本的例子展示如何创建一个卡片组件: ```html <template> <div class="card-demo"> <!-- 简单的 card --> <el-card class="box-card"> <div slot="header" class="clearfix"> <span>卡片名称</span> </div> <div v-for="o in 4" :key="o" class="text item"> {{'列表内容 ' + o }} </div> </el-card> <!-- 带图片的 card --> <el-row style="margin-top: 20px;"> <el-col :span="8" v-for="(item, index) in items" :key="index" :offset="index > 0 ? 2 : 0"> <el-card :body-style="{ padding: '0px' }"> <img src="/path/to/image.jpg" class="image"/> <div style="padding: 14px;"> <span>{{ item.title }}</span> <div class="bottom clearfix"> <time class="time">{{ currentDate }}</time> <el-button type="text" class="button">操作按钮</el-button> </div> </div> </el-card> </el-col> </el-row> </div> </template> <script> export default { data() { return { currentDate: new Date(), items: [ { title: '标题一' }, { title: '标题二' } ] }; } }; </script> <style scoped> .time { font-size: 13px; color: #999; } .bottom { margin-top: 13px; line-height: 12px; } .button { float: right; } .text { font-size: 14px; } .item { margin-bottom: 18px; } .clearfix:before, .clearfix:after { display: table; content: ""; } .clearfix:after { clear: both; } .box-card { width: 480px; } .image { width: 100%; height: auto; } </style> ``` 这段代码展示了两种类型的卡片:一种是带有头部标题的基础卡片;另一种则是带有一张图片以及一些额外信息的卡片[^2]。 #### 属性介绍 | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | bodyStyle | 设置 .el-card__body 样式 | object | `{}` | | shadow | 控制阴影显示时机 | string (`always`, `hover`, `never`) | always | 此表格列出了部分常用的属性配置选项,更多细节可查阅官方文档获取最新最全的信息。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值