给登录添加回车事件
@keydown.enter.native="submitLogin"
问题:
项目中使用了element-ui,在某一个input上绑定了enter的键盘事件,代码如下
<el-form :inline="true">
<el-form-item>
<el-input placeholder="请输入您要搜索内容的关键词" v-model="value" @keyup.native.enter="search"></el-input>
<i @click="search"></i>
</el-form-item>
</el-form>
理论上来说按下回车键会提交查询,然后获取查询结果渲染到页面,但事实是在按下enter的时候浏览器刷新了。。。
浏览器地址栏从
- http://localhost:8080/#/***
变成了
- http://localhost:8080/?#/***
多了个“?”
显然是enter自动提交表单在搞鬼
解决方法:
在form表单上加上 == @submit.native.prevent ==阻止自动提交
修改后的代码如下:
<el-form :inline="true" @submit.native.prevent>
<el-form-item>
<el-input placeholder="请输入您要搜索内容的关键词" v-model="value" @keyup.native.enter="search"></el-input>
<i @click="search"></i>
</el-form-item>
</el-form>