如下代码,建议用这个,e.keyCode 已经过时,后面都是用 e.key:string.
onMounted(() => {
window.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.key === 's') { // 检查是否按下了 Ctrl + S
e.preventDefault(); // 阻止默认行为(保存网页)
console.log(editDocumentVisible.value);
if (editDocumentVisible.value) {
saveDocument();
}
}
});
});
标签:typescript,Ctrl,value,key,Vue3,editDocumentVisible
From: https://www.cnblogs.com/pphboy/p/17361648.html