vue在按钮上绑定enter键
在登录按钮中绑定上enter键话不多说,直接上代码吧~<el-button type="primary" @click="submitForm('loginForm')">登录</el-button>created () {let that = thisdocument.onkeydown = function (e) {e = window.event || e// 验证
·
在登录按钮中绑定上enter键
话不多说,直接上代码吧~
<el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
created () {
let that = this
document.onkeydown = function (e) {
e = window.event || e
// 验证在登录界面和按得键是回车键enter
if (that.$route.path === '/login' && (e.code === 'Enter' || e.code === 'enter')) {
// 登录事件
that.submitForm('loginForm')
}
}
},
此文章参考了别的up主的代码,但是由于昨天写的了 找不到那个博主来@了(●’◡’●)
更多推荐
已为社区贡献11条内容
所有评论(0)