瀏覽代碼

realCount

maryluis 4 年之前
父節點
當前提交
bf70b32dc4
共有 1 個文件被更改,包括 3 次插入2 次删除
  1. 3 2
      shop/src/reducers/cartReducer.js

+ 3 - 2
shop/src/reducers/cartReducer.js

@@ -13,6 +13,7 @@ function cartReducer(state, { type, count, id, image,  name, description,  price
     }
     }
     if (type === "CART_ADD") {
+        //debugger
         state = {
             ...state,
             
@@ -22,7 +23,7 @@ function cartReducer(state, { type, count, id, image,  name, description,  price
                     description: description,
                     image: image,
                     name, name,
-                   count: (count + 1 )|| 0},
+                    count: ((state[id] ? state[id].count : 0) + 1  )},
         };
     }
 
@@ -39,7 +40,7 @@ function cartReducer(state, { type, count, id, image,  name, description,  price
 
 
 
-const actionCartAdd = (name, price, id, description, image, count = 1) => ({
+const actionCartAdd = (name, price, id, description, image, count = 0) => ({
     type: "CART_ADD",
     id,
     count,