js监听按键行为
实例:点击H键实现刷新功能
import { onMounted, onUnmounted } from "vue";
//vue实例挂载后调用
onMounted(() => {
document.addEventListener("keydown", (event) => {
if (event.keyCode == 72) {
location.reload();
}
});
});
//vue实例销毁时调用
onUnmounted("keydown", (event) => {
document.removeEventListener("keydown", () => {});
});
标签:vue,keydown,监听,按键,js,event
From: https://www.cnblogs.com/sxliu414/p/17736051.html