Reputation: 515
In Vue.js i use this part of code in computed to calculate cumule of amounts. It works good in LocalHost. But when i upload the project to a Web Server, this part of code isn't working. Code:
personsWithAmount(){
const reducer = (accumulator, currentValue) => accumulator + currentValue.amount;
return this.persons.map((pers)=>{
let p=pers;
if(pers.usercashfloat.length===0){
p.totalAmount=0;
}else if(pers.usercashfloat.length===1){
p.totalAmount=pers.usercashfloat[0].amount;
}else{
window.cashfloat=pers.usercashfloat
p.totalAmount=pers.usercashfloat.reduce(reducer,0);
};
Result in LocalHost :
Array 1 =200
Array2 = 200
Result = 400
Resultat In Server
Array 1 =200
Array2 = 200
Result = 200200
Thanks
Upvotes: 0
Views: 40
Reputation: 1199
It seems like some string concatination is happening. Perhaps this works:
const reducer = (accumulator, currentValue) => Number(accumulator) + Number(currentValue.amount);
Upvotes: 2