So my question is about binding some keyboard shortcuts, for example v-on:keyup.enter="someEvent()"
to buttons in the UI <button :click="someEvent()">$t{{ nameOfBtn }}<button>
. Perhaps there is a way to combine these two in one tag. I've been playing around with these two bindings but have not got any desirable result.
NB: I cannot use any plugins.
https://v2.vuejs.org/v2/guide/events.html#Key-Modifiers
You can bind keyup handlers, but it might not make sense in a button. Presses in an input field are captured to the element but most others are global to the page. You could add a listener when your component is created though...
{
created: function () {
window.addEventListener('keyup', this.previous)
},
methods: {
previous: function (e) {
// check key code
}
},
beforeDestroy: function () {
// remove listener
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.