From f51ddf203983b248b974ad7f5387382735ea7b6d Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 11 Feb 2020 11:19:31 +0800 Subject: [PATCH] add enter key code --- frontend/src/login/Login.vue | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/frontend/src/login/Login.vue b/frontend/src/login/Login.vue index b707131db9..f8fb291c29 100644 --- a/frontend/src/login/Login.vue +++ b/frontend/src/login/Login.vue @@ -81,7 +81,24 @@ } }); }, + created: function () { + // 主页添加键盘事件,注意,不能直接在焦点事件上添加回车 + document.addEventListener("keydown", this.watchEnter); + }, + destroyed() { + //移除监听回车按键 + document.removeEventListener("keydown", this.watchEnter); + }, methods: { + //监听回车按钮事件 + watchEnter(e) { + let keyNum = e.which; //获取被按下的键值 + //判断如果用户按下了回车键(keycody=13) + if (keyNum === 13) { + // 按下回车按钮要做的事 + this.submit('form'); + } + }, submit(form) { this.$refs[form].validate((valid) => { if (valid) {