javascript - 当产品从购物车中删除时如何更新购物车总摘要
问题描述
我是 Ionic 的新手,目前正在开发一个电子商务应用程序。我已成功显示添加到购物车页面的产品,现在需要实现从总摘要中扣除相关金额的逻辑,如果产品从购物车中删除。
这是我的购物车.ts
removeFromCart(index,item){
this.totalPrice = 0;
let sumTotal = 0;
let price = item.price;
let qty = item.quantity
sumTotal = price * qty;
this.cartData.splice(index,1);
let pId = item.id;
this.storage.remove(`product_${pId}`).then(()=>{
this.totalPrice -= sumTotal
});
}
这总结了购物车中的产品
calculatePrice(){
this.totalPrice = 0;
let tempPrice = 0;
this.baseProducts.forEach((product) => {
tempPrice = product.price * product.quantity;
this.totalPrice += tempPrice
});
return this.totalPrice;
}
解决方案
推荐阅读
- kubernetes - 我可以获得比一次重启前更旧的容器日志吗?
- java - 什么端口使用stomp协议?
- javascript - 使用同步发送一个道具并在孩子中使用 v-model 绑定它
- python - ADB 方法使用 python adb.devices() 冻结
- node.js - 如何在节点 ejs 中显示来自动态路径的图像
- java - 持久的 Google 登录 Android Studio
- python - 如何检测不和谐的用户流活动更新(discord.py)
- javascript - 在所有文件中全局导入 ReactJS 组件
- python - 必须是实数,而不是列表
- javascript - 直接滚动一个div