1、监听
created() {
window.addEventListener('keydown', this.handkeyCode, true) //开启监听键盘按下事件
},
2.触发
// 回车和空格键提交右侧信息
handkeyCode(e) {
if (e.keyCode === 13) {
this.submitForm() // 触发了回车/空格键
}
},
3、销毁
beforeDestroy() {
// console.log('销毁之前触发')
window.removeEventListener('keydown', this.handkeyCode, true) //关闭监听键盘按下事件
},