this.totalInvoiceAmount=this.invoiceList.reduce((prev, next) => {
return prev + next.totalPrice;
},0);
应用reduce方法
错误示例:
//计算累计开票金额
this.totalInvoiceAmount=this.invoiceList.reduce((prev, next) => {
return prev.totalPrice + next.totalPrice;
});
//打印的和为NaN
注解:打印的和为NaN,因为prev是计算前几次之和,没有totalPrice属性,至于为什么后面加个0,i dont know