gpt4 book ai didi

vuejs2 - Vue 2 - 计算输入的总行数

转载 作者:行者123 更新时间:2023-12-01 15:25:20 25 4
gpt4 key购买 nike

我有一个带有数量和价格输入的动态表,我使用计算属性来计算每一行的总数。现在我需要找到一种方法来计算总计(所有小计的总和)。

HTML:

   <tr v-for="(item, index) in items">
<td><input v-model.number="item.qty" size="10"></td>
<td><input v-model.number="item.price" size="10"></td>
<td><input v-model.number="subtotalRow[index]" readonly size="10"></td>
<td><button @click="addRow(index)">+</button></td>
<td><button @click="removeRow(index)">-</button></td>
</tr>
<tr>
<td>Total: {{total}}</td>
</tr>

Javascript:

computed: {
subtotalRow() {
return this.items.map((item) => {
return Number(item.qty * item.price)
});
},
// the index part is confusing me
//
// total() {
// return this.items.reduce((total, ?) => {
// return total + ?;
// }, 0);
//}
},

我提供了一个小 fiddle 来说明问题。

https://jsfiddle.net/h5swdfv5/

我希望一些指导可以帮助我。提前谢谢你

最佳答案

total() {
return this.items.reduce((total, item) => {
return total + item.qty * item.price;
}, 0);
}

工作 fiddle :https://jsfiddle.net/h5swdfv5/1/

关于vuejs2 - Vue 2 - 计算输入的总行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45425607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com