我正在尝试将合计的值相加并找到它们的总和,以在视图中显示,但不知何故不起作用。
export default {
data() {
return {
invoices: [],
}
},
computed:{
sum () {
return invoices.map(function(invoice) {
return invoice.sum.map((inv) => inv.totale).reduce(function (total, inv) {
return total + inv
}, 0);
});
}
},
}
数据图片: Data
答案 0 :(得分:0)
new Vue({
el: '#app',
data() {
return {
invoices: [{ totale: 10 }, { totale: 10 }, { totale: 10 }],
}
},
computed: {
sum() {
return this.invoices.reduce((acc, { totale }) => acc + totale, 0);
}
},
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">{{ sum }}</div>