Return value of the function executed by KeyUp in the source field in VUE

0

How do I get the return value of this function to be inserted into the field where you are running KeyUp?

<input type="text" v-model="valor_calc_dinheiro" v-on:keyup.stop.prevent="mascara_dinheiro($event.target.value)"           ref="valor_calc_dinheiro">

mascara_dinheiro : function(valor){
v=valor.replace(/(\d{1})(\d{1,2})$/,"$1.$2")
alert(v);
},
    
asked by anonymous 08.10.2018 / 15:36

1 answer

0

Pass only the event and thus you have the event.target available for example ...

That is:

<input type="text" v-model="valor_calc_dinheiro" v-on:keyup.stop.prevent="mascara_dinheiro($event)"           ref="valor_calc_dinheiro">

And then in the method:

mascara_dinheiro: function(e){
    const v = e.target.value.replace(/(\d{1})(\d{1,2})$/,"$1.$2")
    alert(v);
    e.target.value = v;
},

Note: Note that I put const v and not only v . You should avoid global variables, it is always important to declare variables before using them. You can read more about it here: var, const, or let? Which one to use?

    
12.10.2018 / 07:49