Vue
HTML
<div id="app">
USD:<input type="number" v-model="priceInUSD" />
RUB: <input type="number" v-model="priceInRub" />
</div>
Vue
new Vue({
el: "#app",
data: {
statePriceInUSD:0,
statePriceInRub: 0,
rate: 65.395402,
},
computed: {
priceInUSD: {
get(){
return this.statePriceInUSD;
},
set(newValue){
console.log('USD new value: ' + newValue);
this.statePriceInUSD = newValue;
this.statePriceInRub = newValue * this.rate;
}
},
priceInRub: {
get(){
return this.statePriceInRub;
},
set(newValue){
console.log('RUB new value: ' + newValue);
this.statePriceInRub = newValue;
this.statePriceInUSD = +newValue / this.rate;
}
},
}
})