Within the created()
hook, I have the code below:
{
created() {
window.addEventListener('keydown', this.someMethod)
},
methods: {
someMethod(event) {
console.log(event)
// perform actions
}
}
}
The issue is that the console log is not appearing. Where am I making a mistake? The following solution has proven to be successful:
const someMethod = event => {
console.log(event)
}
export default {
... other content
created() {
window.addEventListener('keydown', this.someMethod)
},
}
UPDATE:
It appears there is some confusion surrounding my inquiry. My question does not pertain to using the this
keyword within the function, as an arrow function addresses this concern. My query revolves around the inability to pass the object's method as the callback function.