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