I am looking to utilize Vue's two-way data binding to dynamically update the values of amount
and total
. The price of a given product is fixed. When users modify the amount
, the total = amount * total
will be automatically calculated. Similarly, users can input the total
and the amount = total / price
will be computed accordingly. However, I am currently stuck at this stage:
var app = new Vue({
el: '#app',
data: {
amount: 1,
price: 100,
},
computed: {
calcTotal: function() {
return this.total =
parseFloat(this.amount) *
parseFloat(this.price)
}
}
})
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div id="app">
amount: <input v-model="amount"> <br><br> price: <input v-model="price" disabled> <br><br> total: <input v-model="calcTotal"> <br><br>
</div>