在login.vue中created()鉤子函數(shù)中
created() {
//回車鍵直接登錄
let that = this;
document.onkeypress = function(e) {
var keycode = document.all ? event.keyCode : e.which;
//需要注意的:that.$route.path==''/login'的作用是如果不判斷,回車可能所有頁面都生效,也就是無論在哪個(gè)頁面敲回車都會直接登錄
if (that.$route.path=='/login'&& keycode == 13) {
that.handleSubmit('formLogin');// 登錄方法名
return false;
}
};
},