vue项目触发回车键登录
created() {
let that = this;
document.onkeydown =function(e){
e = window.event || e;
if(that.$route.path=='/login'&&(e.code=='Enter'||e.code=='enter')){//验证在登录界面和按得键是回车键enter
that.submitForm('loginForm');//登录函数
}
}
}
全局监听即可,不用绑定什么事件,很方便