<template slot="footer" slot-scope="scope">
<el-table-row style="float: right">
<el-table-cell
class="text-right"
style="font-family: 微软雅黑; font-weight: 900"
>合计:</el-table-cell
>
<el-table-cell class="text-right"
>借款金额:{{
"¥" + getTotalBorrowAmount().toFixed(2)
}}</el-table-cell
>
<el-table-cell class="text-right"
>贷款金额:{{
"¥" + getTotalLendAmount().toFixed(2)
}}</el-table-cell
>
</el-table-row>
</template>
第二步:通过计算属性:computed()用来暂存数据
computed: {
borrowAmounts() {
return this.loadData.map((item) => parseFloat(item.borrower) || 0);
},
lendAmounts() {
return this.loadData.map((item) => parseFloat(item.lender) || 0);
},
},
第三步:通过reduce()来计算所有的值
// 计算总额
getTotalBorrowAmount() {
return this.borrowAmounts.reduce((total, amount) => total + amount, 0);
},
getTotalLendAmount() {
return this.lendAmounts.reduce((total, amount) => total + amount, 0);
},