全局監聽enter鍵,是把監聽事件綁定到document上,無需獲取焦點之類的
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');//登錄函數 } } }