computed: {
// totalPrice: function () {另一种定义方式
totalPrice() {
//计算总价的实现思路
//遍历购物车,所有的商品 价格*数量 进行累加
let sum = 0;
for (let i = 0; i < this.carts.length; i++) {
sum += this.carts[i].count * this.carts[i].price;
}
return sum;
},
}
购物金额总计:<strong>¥ <span id="total">{{ totalPrice }}</span></strong>