Hay dos filas de fila de datos,
<tr v-for="(data, index) in result_estimate.item_tabel" :key="index"> <td> <pre> sub total : {{ambilaja(formatPrice(ambilPrice[index] - (ambilPrice[index] * subtotalRow[index])))}}</pre> </td> <tr> <div> total : {{this.totals}}</div>El resultado del valor anterior es el total de cada una de cada fila, aquí le paso el valor a la función ambilaja().
return { totals : 0 }, computed : (){ ambilaja: function(){ return (value) => this.lempar(value) }, }, method : { lempar(data){ console.log(data) result console 30002 -> total row index 0 2003 -> total row index 1 } }¿Cómo sumar el total? ej: 30002 + 2003 = este.totales
No estoy seguro de qué tipo de datos hay en ambilPrice o subtotalRow, pero puede agregar otro método y pasar parámetros para hacer cálculos.
<tr v-for="(data, index) in result_estimate.item_tabel" :key="index"> <td> <pre> sub total : {{ambilaja(formatPrice(ambilPrice[index] - (ambilPrice[index] * subtotalRow[index])))}}</pre> </td> <tr> <div> total : {{calTotals(ambilPrice, ambilPrice, subtotalRow)}}</div>Código Vue:
return { totals : 0 }, method : { calTotals(ambilPriceArr, subtotalRow, index) { this.totals = this.totals + ambilPriceArr[index] - (ambilPriceArr[index] * subtotalRow[index]); return this.totals; }, }El mejor enfoque para este problema es usar la propiedad computed para el total como se muestra a continuación.
computed() { total: function(){ let sum = 0; this.result_estimate.item_tabel.forEach(item => sum += this.calculatePriceForIndividualRow(item)); return sum; }, }, calculatePriceForIndividualRow es la función que calculará la suma para cada fila.