Skip to content

Instantly share code, notes, and snippets.

@Lelectrolux
Last active March 21, 2020 17:25
Show Gist options
  • Save Lelectrolux/71673544452a9911934ce935dc4ac39b to your computer and use it in GitHub Desktop.
Save Lelectrolux/71673544452a9911934ce935dc4ac39b to your computer and use it in GitHub Desktop.
<template>
<div>
<event-listener @keydown.space="doSomething">
...
</div>
</template>
<script>
export default {
methods: {
doSomething () {
// Start-stop a video for example
}
}
}
</script>
export default {
render () {},
mounted () {
Object.keys(this.$listeners)
.foreach(event => {
window.addEventListener(event, this.$listeners[event])
})
},
destroyed () {
Object.keys(this.$listeners)
.foreach(event => {
window.removeEventListener(event, this.$listeners[event])
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment