<input id="phone" v-model="phone" type="text" :placeholder="i18n.mobileNumber" @keypress="isNumber()"
/>
Copy the code
methods:
isNumber() {
let evt = window.event;
console.log(evt.which)
var charCode = (evt.which) ? evt.which : evt.keyCode;
if((charCode > 31 && (charCode < 48 || charCode > 57)) && charCode ! = =46) {
evt.preventDefault();
} else {
return true; }}Copy the code