I have a vue (version 2.x) file where I have 3 fields - input1 x input2 = result
Now, when I change any one of them, the other two should be updated on the fly.
I tried using watch property but that leads to infinite loop because the watchers keep calling each other.
Is there any vue related helper which I am missing here? Any help would be appreciated.
Refer this for example code.
<template>
<input v-model="input1"></input>
<input v-model="input2"></input>
<input v-model="conversionRate"></input>
</template>
<script>
export default {
data() {
input1: null,
input2: null,
conversionRate: null
},
watch: {
input1() {
this.input2 = this.input1 * this.conversionRate
},
input2() {
this.input1 = this.input2 * this.conversionRate
},
conversionRate() {
this.input2 = this.input1 * this.conversionRate
}
}
}
</script>
input1andinput2if we editresult?@inputand:value=instead ofv-modeland use intermediate values to prevent this effect of infinite loop. (currency1InputValue->currency1,currency2InputValue->currency2, etc...)