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

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

Posted by: admin November 26, 2021 Leave a comment

Questions:

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

Answers:

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

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