![cover](https://img-blog.csdnimg.cn/0b15a4f05c93487e8b4a6f6bc9386409.jpeg)
#vue#使用Element输入框,使用enter回车键搜索或提交
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
![](https://devpress.csdnimg.cn/6deffb34f7114cc1a2e1e686a67e0027.png)
·
搜索
如果整个表单只有一个输入框,按enter键实现搜索
<el-input @keyup.enter.native="toFilterData"
v-model="formInline.students_name" ></el-input>
同时进行监听有没有输入值,在methods里,写上监听的方法,当获取的v-model里的值,按下了回车键,如果需要监听空格或者其他键,换成别的键值
// //查询
toFilterData() {
// 当用户没有输入内容就按enter键时,就return,不做任何操作,不去搜索
if(this.formInline.students_name === '') {
return
} else {
// 请求查询接口,将列表展现出来
this.getTabletsIndex();
}
},
vue+elementUI在输入框中按回车键如果依旧会刷新页面;问题原因:当一个 form 元素中只有一个输入框时,在该输入框中按下回车应提交该表单。如果希望阻止这一默认行为,可以在 <el-form> 标签上添加 @submit.native.prevent。
<el-form @submit.native.prevent></el-form>
提交
输入密码以后,按enter键即可登录成功
只需要在输入框和按钮加入以下代码即可
<el-form-item prop="password">
<el-input
ref="password"
v-model="loginForm.password"
:type="passwordType"
placeholder="请输入密码"
tabindex="2"
@keyup.enter.native="handleLogin" />
</el-form-item>
<el-button :loading="loading" @click.native.prevent="handleLogin" >登录</el-button>
![]( https://profile-avatar.csdnimg.cn/default.jpg)
![](https://devpress.csdnimg.cn/7174e1ca86c447029bb12f9ec0bd281c.png)
![](https://devpress.csdnimg.cn/096f7827187446559bd7b6030eb5db38.png)
![](https://devpress.csdnimg.cn/6deffb34f7114cc1a2e1e686a67e0027.png)
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:4 个月前 )
c345bb45
8 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 8 个月前
更多推荐
所有评论(0)