element-ui el-button点击后不失焦

博客地址:http://www.globm.top/blog/1/detail/14
使用element ui库,发现button点下去之后会一直保持被点击的状态直到鼠标在别的地方点一下才恢复。也就是说button被点击之后一直没有失焦,直到点击别的地方,将焦点切换走

如果按钮有按键监听行为,那么当按钮在聚焦状态下也会触发,比如点击button打开模态窗时调用了一个方法openDialog,如果按钮未失去焦点,那么通过按键可能会再次触发该方法,所以需要手动移除聚焦效果

openDialog(ev) {
 ev.target.blur()
},
### 使用 Element-UIel-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 | 此表格列出了部分常用的属性配置选项,更多细节可查阅官方文档获取最新最全的信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萝卜砸大坑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值