Skip to content

Instantly share code, notes, and snippets.

@susanBuck
Created October 16, 2019 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save susanBuck/405e680d7efc00595139aec7427f5e56 to your computer and use it in GitHub Desktop.
Save susanBuck/405e680d7efc00595139aec7427f5e56 to your computer and use it in GitHub Desktop.
Vue.js listen for keypress example for Norcius
let app = new Vue({
el: '#app',
methods: {
isAlpha: function (ch) {
return /^[A-Z]$/i.test(ch);
},
checkForLetter(letter) {
console.log(letter);
}
},
mounted() {
window.addEventListener('keypress', function (e) {
if (this.isAlpha(event.key)) {
this.checkForLetter(event.key.toUpperCase())
}
}.bind(this));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment