javascript - How to add constraints to v-model -


in terms of vuejs:

how add constraints(limits) v-model properly? let's want allow numbers between 0 , 5.

<input type="number" v-model="model"/> 

perhaps can watch input's value. it's bit hacky, isn't it?

upd: other option handle onchange, onkeyup , etc , other events: html text input allow numeric input

don't abuse watch this. use binding , event method:

<input type="number" v-bind:value="model" @input="handleinput"/> 

js:

methods: {   handleinput: function(event) {     var value = number(event.target.value)     if (value > 5) {       this.model = 5     }     elseif (value < 0 || number.isnan(value)) {       this.model = 0     }     else       this.model = value     }   } } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -