在Vue.js中,我使用计算的这部分代码来计算金额累计。它在LocalHost中工作良好。但是,当我将项目上传到Web服务器时,这部分代码无法正常工作。 代码:
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);
};
LocalHost的结果:
Array 1 =200
Array2 = 200
Result = 400
服务器中的结果
Array 1 =200
Array2 = 200
Result = 200200
谢谢
答案 0 :(得分:2)
似乎正在发生一些字符串混淆。也许这可行:
const reducer = (accumulator, currentValue) => Number(accumulator) + Number(currentValue.amount);