在登录按钮中绑定上enter键
话不多说,直接上代码吧~
javascript"> <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
javascript"> 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主的代码,但是由于昨天写的了 找不到那个博主来@了(●’◡’●)