v-on:keyup test
HTML
<script src="https://unpkg.com/vue@2.5.13/dist/vue.js"></script>
<div id="app">
<button @click="popupLeft">Prev Page</button>
<button @click="popupRight">Next Page</button>
<button @click="popupClose">Close Page</button>
</div>
JavaScript
new Vue({
el: "#app",
methods: {
popupLeft: function(){
alert("You have gone to the previous page");
},
popupRight: function(){
alert("You have gone to the next page");
},
popupClose: function(){
alert("You have closed this page");
},
handleKeydown (e) {
switch (e.keyCode) {
case 37:
this.popupLeft();
break;
case 39:
this.popupRight();
break;
}
}
},
beforeMount () {
window.addEventListener('keydown', this.handleKeydown, null);
},
beforeDestroy () {
window.removeEventListener('keydown', this.handleKeydown);
}
})