yassine j
yassine j

Reputation: 515

This part of my VueJs code isn't working in server

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

Answers (1)

peerbolte
peerbolte

Reputation: 1199

It seems like some string concatination is happening. Perhaps this works:

const reducer = (accumulator, currentValue) => Number(accumulator) + Number(currentValue.amount);

Upvotes: 2

Related Questions