1.在mounted中创建键盘监听
mounted() {
window.addEventListener("keydown", this.KeyDown, true);
},
2.然后在methods中直接写入事件即可在整个页面监听
KeyDown(e) {
console.log(e.key, e.keyCode);
if (e.key === "Enter" || e.keyCode === 13) {
console.log("检测到按下了回车键");
}
},