Sometimes, we want to fix @keyup
event not working with the enter key pressed on a button in Vue.js.
In this article, we’ll look at how to fix @keyup
event not working with the enter key pressed on a button in Vue.js.
How to fix @keyup event not working with the enter key pressed on a button in Vue.js?
To fix @keyup
event not working with the enter key pressed on a button in Vue.js, we should replace @keyup
with @click
to listen to the click event.
For instance, we write
<template>
<div>
<button @click="callEvent">Enter</button>
</div>
</template>
to listen to the click event with @click="callEvent"
.
Pressing enter on a button will trigger the click event.
Conclusion
To fix @keyup
event not working with the enter key pressed on a button in Vue.js, we should replace @keyup
with @click
to listen to the click event.