vuejs ,获取对象里到值循环累加问题

carts=["goods_list": {
    "charm祺舰店": [
                    {
                        "shop": "charm祺舰店",
                        "id": 51,
                        "url": "http://gd3.alicdn.com/imgextra/i4/2945370550/TB2mBzscYSYBuNjSspfXXcZCpXa_!!2945370550.jpg_400x400.jpg",
                        "name": "衬衫2018新款小衫上衣女装宽松韩版百搭春秋超仙甜美长袖女雪纺衫",
                        "price": "169.00",
                        "quantity": 1,
                        "attr": "尺码:2XL 颜色分类:黑色",
                        "cn_base_ship": "10.00",
                        "rec_type": 0,
                        "remark": null,
                        "img": "http://gd3.alicdn.com/imgextra/i4/2945370550/TB2mBzscYSYBuNjSspfXXcZCpXa_!!2945370550.jpg_400x400.jpg",
                        "is_fba": 0,
                        "sn": "TAOBAO_565168354699",
                        "goods_total": "169.00",
                        "checked": false
                    },
                    {
                        "shop": "charm祺舰店",
                        "id": 52,
                        "url": "http://gd3.alicdn.com/imgextra/i4/2945370550/TB2mBzscYSYBuNjSspfXXcZCpXa_!!2945370550.jpg_400x400.jpg",
                        "name": "衬衫2018新款小衫上衣女装宽松韩版百搭春秋超仙甜美长袖女雪纺衫",
                        "price": "169.00",
                        "quantity": 1,
                        "attr": "尺码:2XL 颜色分类:白色",
                        "cn_base_ship": "10.00",
                        "rec_type": 0,
                        "remark": null,
                        "img": "http://gd3.alicdn.com/imgextra/i4/2945370550/TB2mBzscYSYBuNjSspfXXcZCpXa_!!2945370550.jpg_400x400.jpg",
                        "is_fba": 0,
                        "sn": "TAOBAO_565168354699",
                        "goods_total": "169.00",
                        "checked": false
                    }
                    ],
    "东莞市龙企日用品有限公司": [
                            {
                                "shop": "东莞市龙企日用品有限公司",
                                "id": 53,
                                "url": "https://cbu01.alicdn.com/img/ibank/2017/312/250/7378052213_663451055.jpg",
                                "name": "黑色经典28包装本色纸餐巾纸卫生纸竹纤维纸抽纸小规格270张包邮",
                                "price": "2.90",
                                "quantity": 1,
                                "attr": "None",
                                "cn_base_ship": "10.00",
                                "rec_type": 0,
                                "remark": null,
                                "img": "https://cbu01.alicdn.com/img/ibank/2017/312/250/7378052213_663451055.jpg",
                                "is_fba": 0,
                                "sn": "1688_562251109331?scm=1007.17269.96789.0",
                                "goods_total": "2.90",
                                "checked": false
                            }
                            ]
                        }]
        calcTotalmoney: function () {
            var self = this;
            var totalMoney =  0;
            this.carts.forEach(function (item) {
                item.forEach(function (g) {
                    self.totalMoney += g.price * g.quantity;
                });
            });
        }
错误提示是 carts.forEach is not function

想得出循环累加 单价 * 数量。。。 谢谢

阅读 1.6k
评论
    3 个回答
    • 537

    首先,你的最外层应该是花括号

      相似问题
      推荐文章