使用计算属性获取商品总额

 computed:{
                sum : function(){
                    return this.list.length
                },
                suma:function(){
                    let a = 0;
                  this.list.forEach(function(x,index){
                     a = a + x.price
                   })
                   return a
                }
            },

foreach具有作用域,容器a需要在循环体外声明,

posted @ 2020-06-30 16:09  好啊好呀  阅读(176)  评论(0)    收藏  举报