【问题标题】:This part of my VueJs code isn't working in server我的这部分 VueJs 代码在服务器中不起作用
【发布时间】:2019-01-02 16:00:42
【问题描述】:

在 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

谢谢

【问题讨论】:

    标签: laravel vue.js


    【解决方案1】:

    似乎正在发生一些字符串连接。也许这行得通:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      • 2018-08-06
      • 2021-03-29
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多