[Vuejs]-Implementing @keypress in Vue

3👍

Figured out the problem. Though I was returning a boolean when reading the keyCodes, I wasn’t preventing the default keypress action. The restrictChars method should look something like this!

restrictChars: function($event) {
    if ($event.charCode === 0 || /\d/.test(String.fromCharCode($event.charCode))) {
        return true
    } else {
        $event.preventDefault();
    }
}

Leave a comment