vue通过快捷键保存 ctrl+s或者command+s
文章目录
直接上代码
save (e) {
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
// 执行save方法
this.save()
// 阻止默认事件
e.preventDefault()
}在mounted里通过addEventListener监听
document.addEventListener('keydown', this.save, false)别忘记在离开页面的时候在destroyed里面销毁
document.removeEventListener('keydown', this.save, false)
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论