Answer the question
In order to leave comments, you need to log in
How to keep track of two fields in Vue.js so they don't fire in sequence?
I am writing a calculator
. There are 2 fields with v-model that I follow through watch.
Each watch has its own function that is processed when one field changes and is written to another.
The problem is that the function from watch is launched immediately (field A changes B, B changes A), a kind of mini recursion.
How can I make it so that when the data is changed by the user, watch is triggered, but not when I write the data?
Answer the question
In order to leave comments, you need to log in
if it helps anyone:
watch - use when there is only 1 v-model parameter and other inputs do not depend on it
computed (get, set) + storage variable - when the data depends on each other
I will explain in more detail:
I had 2 inputs, you need to when the field data (any) was changed, the
USD rate was recalculated, the RUB rate
used watch and it turned out that due to an error, the script fell into a cycle, because followed two fields
if to use computed - that everything is OK.
thanks to all
I also didn’t quite understand the problem, but if I understood correctly, then add a modifier to the directive: v-model.lazy="..." This modifier subscribes to the change event, not to the input event, and the change event occurs after value has changed and input is terminated, eg input passed and focus lost. Read more here.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question