In my created()
hook, I have the following code:
{
created() {
window.addEventListener('keydown', this.someMethod)
},
methods: {
someMethod(event) {
console.log(event)
// do stuff
}
}
}
The console log is not firing. What am I doing wrong? The following works:
const someMethod = event => {
console.log(event)
}
export default {
... other stuff
created() {
window.addEventListener('keydown', this.someMethod)
},
}
EDIT:
There seems to be some confusion about what I'm asking. I'm not asking how I can use this
keyword inside the function. You use the arrow function for that. What I'm asking is I can't seem to pass the object's method as the callback function.