为什么不把购物车的count为的进行删除,二是count为0的仅仅不显示?
来源:12-10 购物流程开发完成(2)

qq_Simpleisbeau_0
2022-03-07
store/index.js的商品修改changeCartItemInfo 函数
changeCartItemInfo (state, payload) {
const { shopId, productId, productInfo, num } = payload
const shopInfo = state?.cartList?.[shopId] || {
shopName: '', productList: {}
}
let product = shopInfo.productList[productId]
if (!product) {
productInfo.count = 0
product = productInfo
}
product.count += num
if (num > 0) product.isCheck = true
if (product.count <= 0) {
delete shopInfo.productList[productId]
} else {
shopInfo.productList[productId] = product
}
state.cartList[shopId] = shopInfo
setLocalCartList(state)
}
这样写可否,我直接把count为0,用“delete shopInfo.productList[productId]”给删了。实际开发也是对这些数据软删除吗,有什么深层含义吗,请老师告知。
写回答
1回答
-
Dell
2022-03-12
不建议这么操作,因为你用的vue proxy 生成的对象,这么操作有可能会有意想不到的额外 bug
012022-03-17
相似问题