Skip to content
Advertisement

How to set value of argument event target on vue?

I have an input value using debounce plugin, that passing to the event. The input dom is based on an array inside looping. At some conditions, I need to set the value that the input box to “0” from the event action after being compared with another data. How to do that?

My template code

JavaScript

Vue method :

JavaScript

Have tried :

JavaScript

Advertisement

Answer

Do not change the value of the input element in the DOM. Change the data bound as v-model

To get access to correct item in the event handler, just pass the item into the handler and use $event to pass the original event data as well (if you actually need it)

JavaScript

Now you can change item.qty inside CalculateItem and Vue will update the content of the <input>

Also note that when creating debounced function like that, there is only one debounced function for all instances of given component – see the docs (yes, the docs are for Vue 3 but same applies to Vue 2)

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement