I see this topic, But this is Jquery, How can I change it to Vue.js ? Is v-on supported in Vue.js Where is my mistake. Sorry for my terrible English.
<div id="vue">
<input v-model="amountModel" v-on:keyup="AddCammas()" value="{{price}}">
</div>
<script>
el: #vue,
methods:{
AddCammas : funtion(){
if(event.which >= 37 && event.which <= 40) return;
$(this).val(function(index, value) {
this.message = this.amountModel
.replace(/\D/g, "")
.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
});
}
}
</script>
To people who are looking for doing mask for multiple fields then it's kinda pain to use
watch
, so may we can use v-money (docs included). And check the demo here.You don't need jQuery at all for this. You
watch
your variable, and in the watch function, compute the reformatted version, then set it back to your variable usingnextTick
(so it's not mutating before the watch is complete).