Created
October 16, 2019 17:20
-
-
Save susanBuck/405e680d7efc00595139aec7427f5e56 to your computer and use it in GitHub Desktop.
Vue.js listen for keypress example for Norcius
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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