elementUI el-input focus
- Q1. el-input 获取焦点
- Q2. dialog中的 el-input获取焦点
- Q3. dialog中有table table中有 el-input 要获取焦点
一个宗旨: this.$refs.XXX.$el.querySelector('input').focus();
answer 1
<el-input ref="mark"></el-input>
使用时直接 (对于多个el-input也是一样的)
this.$refs.mark.$el.querySelector('input').focus();
answer 2
需要在dialog打开时候让input获取焦点
<el-dialog
title="销售员"
:visible.sync="customerVisible"
@open="customerDialogOpen" // 这个是重点
>
<el-input ref="customerInput" ></el-input>
</el-dialog>
//销售员 dialog 打开时 获取焦点
customerDialogOpen() {
this.customerVisible = true
this.$nextTick(function () {
this.$refs.customerInput.$el.querySelector('input').focus();
});
},
answer 3
<el-dialog title="结账" :visible.sync="sumVisible"
:close-on-click-modal="false"
@open="sumDialogOpen">
<el-table
:data="tableData"
size="mini"
style="width: 100%">
<el-table-column
prop="code"
label="编号"
width="50">
</el-table-column>
<el-table-column
prop="way"
label="结算方式"
width="80">
</el-table-column>
<el-table-column
label="金额">
<template slot-scope="scope">
<el-input size="mini" :ref="scope.row.ref" //看这里看这里
@keyup.up.native="up2pre(scope.row.ref)"
@keyup.down.native="down2next(scope.row.ref)">
</el-input>
</template>
</el-table-column>
...
</el-table>
</el-dialog>
tableData : [
{
code: '01',
way: '现金',
disabled: true,
ref: 'input1',
}, {
code: '02',
way: '银行卡',
disabled: false,
ref: 'input2',
}
]
下面就清楚了吧,跟上面2 的套路一样
//结算 dialog 打开时 获取焦点
sumDialogOpen() {
this.sumVisible = true
this.$nextTick(function () {
this.$refs.input2.$el.querySelector('input').focus();
});
},
至于多个input之间焦点如何切换,
down2next(e) {
let input
switch (e) {
case "input1":
input = `input2`
break
case "input2":
input = `input3`
break
}
this.$refs[input].$el.querySelector('input').focus();
},
各位兄台有没有便捷的方法?总感觉这样写的好蠢 啊,:smile:
作者:小学生的博客
链接:https://www.jianshu.com/p/63bfbbbd1e82
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
elementUI el-input focus的更多相关文章
- input:focus
input:focus,select:focus,textarea:focus{outline:-webkit-focus-ring-color auto 5px;outline-offset:-2p ...
- ios下input focus弹出软键盘造成fixed元素位置移位
正常状态下 input focus软键盘弹出时 问题描述: 头部结构fixed,滚动到下部内容区域,input.textarea等focus弹出软键盘时,头部位置偏移被居中(该问题ios7 beta3 ...
- 移动端解决input focus后键盘弹出,高度被挤压的问题
//解决弹出键盘页面高度变化bug var viewHeight = window.innerHeight; //获取可视区域高度 $("input").focus(functio ...
- 解决IOS safari在input focus弹出输入法时不支持position fixed的问题
该文章为转载 我们在做移动web应用的时候,常常习惯于使用position:fixed把一个input框作为提问或者搜索框固定在页面底部.但在IOS的safari和webview中,对position ...
- elementUi中input输入字符光标在输入一个字符后,光标失去焦点
elementUi中input输入字符光标在输入一个字符后,光标就退出,无法输入需要再次聚焦然后输入一个字符又再次退出 首先,用elementUi正常用v-model绑定输入的值是不会造成光标退出的, ...
- vue2.0 element-ui中input的@keyup.native.enter='onQuery'回车查询刷新整个表单的解决办法
项目中用的element-ui是v1.4.3版本 实现的功能是在input中输入查询的名称,按下键盘回车键,可以查询表格中数据 问题是,我输入名称,按下回车,会整个表单刷新,搜索条件也被清空:代码如下 ...
- 解决IE与FF 中 input focus 光标移动在最后的方案
只要把input元素的id传进来即可 function moveCursor(id) { var id = document.getElementById(id); id.focus(); var ...
- elementUI 设置input的只读或禁用
只读:readonly 在data里定义:readonly: true, 然后在input框里加上readonly就可以了. 禁用:disabled 在data里定义:edit: true, 然后在i ...
- element-ui 设置input的只读或禁用
只读:readonly 在data里定义:readonly: true, 然后在input框里加上readonly就可以了. 禁用:disabled 在data里定义:edit: true, 然后在i ...
- input.focus()在IOS上失效的解决方法
之前在iphone上做开发时遇到一个问题,在一般的正常浏览器上输入以下代码: 1 2 var apple = document.getElementById('abc'); apple.focus() ...
随机推荐
- C#计算字符串长度,汉字算两个字符
在C#中的字符串类String中,有个Length属性表示字符串的长度,但该字段返回的是字符的个数,如果字符串中含有中文字符的话,一个汉字占用两个字符的长度,此时获取的长度就不够精确,当然也看具体业务 ...
- 结构型---外观模式(Facade Pattern)
定义 外观模式提供了一个统一的接口,用来访问子系统中的一群接口.外观定义了一个高层接口,让子系统更容易使用.使用外观模式时,我们创建了一个统一的类,用来包装子系统中一个或多个复杂的类,客户端可以直接通 ...
- linux基本命令手册
常用指令 ls 显示文件或目录 -l 列出文件详细信息l(list) -a 列出当前目录下所有文件及目录,包括隐藏的a(all) mkdir ...
- EF C# ToPagedList方法 The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must ……
报错信息:The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' ...
- DirBuste 使用
https://sourceforge.net/projects/dirbuster/ 官网下载 记得安装java 运行环境 这是扫描 443 端口的数据 也可以自己写字典规则 在选择模糊查询时 下面 ...
- Laravel5性能优化技巧
分享一些 Laravel 开发的最佳实践,还有调优技巧,后面陆续整理中 1.配置缓存信息 使用laravel自带的artisan命令,将所有config里面的配置都缓存到一个文件里. php arti ...
- 【Java每日一题】20170315
20170314问题解析请点击今日问题下方的“[Java每日一题]20170315”查看(问题解析在公众号首发,公众号ID:weknow619) package Mar2017; public cla ...
- MyBatis:GeneratorConfig生成mapper以及pojo
首先我们需要导入相应的依赖 之后需要针对的配置一些数据 接着我们需要针对性的写配置文件,在根目录下写mybatis的主要配置文件 如上图我们配置了数据库连接.对应的一些pojo.mapper.java ...
- Netty 系列二(传输).
一.前言 上一篇文章我们提到 Netty 的核心组件是 Channel.回调.Future.ChannelHandler.EventLoop,这篇文章主要是对 Channel (Netty传入和传出数 ...
- js 属性增改删操作
js 属性增改删操作,可参看菜鸟教程,这里记录一个小问题:disabled属性 使用setAttribute操作无法 禁用disabled属性,需使用removeAttribute操作,原因是只要有d ...