计算购物车商品数量方法

2022-04-21  本文已影响0人  shine001

this.shopCart是接口拿到的购物车对象 遍历对象中的num

 goodsNum() {
                let num = 0;
                Object.values(this.shopCart).forEach((goods, index) => {
                    num += Number(goods.num);
                });
                if (num > 0) {
                    return num;
                }
            },

上一篇 下一篇

猜你喜欢

热点阅读