Vue计算

2019-03-13  本文已影响0人  莫以有

简单计算手机的总价:

 {{goods.属性名}}
goodsList: [{
                id: ,
                name: '',
                super: '',
                imgurl: '',
                price: ,
                count: 
                    }   
            ]
computed: {
                    totalPrice: function() {
                        var totalPrice = 0;
                        var len = this.goodsList.length;
                        for (var i = 0; i < len; i++) {
                            totalPrice += this.goodsList[i].price * this.goodsList[i].count;
                        }
                        return totalPrice;
                    },
settlement: function() {
                        this.show = true;
                        var totalCount = 0;
                        var len = this.goodsList.length;
                        for (var i = 0; i < len; i++) {
                            totalCount += this.goodsList[i].count;
                        }
                        return totalCount;
                    }
       /* 垂直方向居中 */
        align-items: center;
        /* 水平方向居中 */
        justify-content: center;
       /*手机的个数限制在不能为零以下*/
        disabled="goods.count===0
上一篇下一篇

猜你喜欢

热点阅读