Answer the question
In order to leave comments, you need to log in
How, when entering a value into an input, substitute a new value into the adjacent one?
<td><input type="text" class="form-control" v-model="result[product.id]" /></td>
<td>{{product.unit}}</td>
<td><input type="text" class="form-control" v-model="price[product.id]" v-on:keyup="priceChange" :product_id="product.id" /></td>
<td><input type="text" class="form-control" v-model="sum[product.id]" /></td>
methods: {
priceChange: function(){
let product_id=event.target.getAttribute('product_id');
let price=this.price[product_id];
let count=this.result[product_id];
let sumres=price*count;
console.log(sumres);
this.sum[product_id]=sumres;
}
},
Answer the question
In order to leave comments, you need to log in
Remove keyup event handling and product_id attribute binding; cut priceChange method.
Replace v-model="sum[product.id]"
with :value="sum[product.id]" readonly
.
Make the sum property calculable:
sum() {
return Object.fromEntries(Object.entries(this.price).map(n => ([
n[0],
(this.result[n[0]] || 0) * n[1],
])));
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question