JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://unpkg.com/vue@2.6.14/dist/vue.js"></script>
<div id="app">
USD:
<input type="number" step="0.01" :value="usd.toFixed(2)" @change="updated_usd">
<br>
DOGE:
<input type="number" step="0.001" :value="doge.toFixed(3)" @change="updated_doge">
<br>
The other will update on focus change. Haven't gotten this working with @input yet.
</div>
JavaScript
const USD_TO_DOGE = 7
const DOGE_TO_USD = 1/USD_TO_DOGE;
new Vue({
el: '#app',
data () {
return {
usd: 1,
doge: 7,
}
},
methods: {
updated_usd(event) {
this.usd = event.target.valueAsNumber;
this.doge = this.usd * USD_TO_DOGE;
},
updated_doge(event) {
this.doge = event.target.valueAsNumber;
this.usd = this.doge * DOGE_TO_USD;
},
},
});