mounted () {
this.bodyListener = (e) => {
if (e.keyCode === 13 && e.target === document.body){
if(!this.cashierDialog){
document.getElementById('cashier-cash-btn').click()
}else{
document.getElementById('cashier-dialog-submit').click()
}
}
if(this.cashierDialog){
if (e.keyCode === 27 && e.target === document.body){
document.getElementById('cashier-dialog-cancel').click()
}
}
}
document.body.addEventListener('keyup', this.bodyListener, false)
},
//在实例销毁之前,从body上面移除这个方法
beforeDestroy() {
document.body.removeEventListener('keyup', this.bodyListener)
},
本文转载自:https://www.cnblogs.com/ilovexiaoming/p/7692067.html