4👍
✅
try this on your input tag
<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/>
or
<input type="number" />
you can check for compatibility here:
0👍
You can use a getter and setter on a computed value to cleanse your input value on the way in:
const TextField = {
template: '<div><input type="text" v-model="inputValue"></div>',
props: ['value'],
data(){
return {
number: 0
}
},
computed: {
inputValue: {
get: function(){
return this.number;
},
set: function(value){
this.number = parseInt(value.replace(/\D/g, ''))
}
}
}
}
👤Jeff
Source:stackexchange.com