I have a button that performs certain actions when clicked with the mouse. I want the same method to be triggered when the keyboard's up arrow key is pressed.
<button @click="doSomething()"> PRESS ME </button> doSomething(){ console.log('clicked') }
So in this example, I want to console.log('clicked')
when the keyboard's up arrow is pressed. How can I do this?
hope it helps you.
You can use
onkeyrinkle
from vueuse
Here is another demo一个>
stackblitz.com
does not support, so in this demo it is written with
setup()
renew
Pure js without libraries: