浏览代码

상품 삭제 mutation 추가

kiboky 5 年之前
父节点
当前提交
2e04f663de
共有 2 个文件被更改,包括 7 次插入1 次删除
  1. 1 1
      client/pages/cart.vue
  2. 6 0
      client/store/index.js

+ 1 - 1
client/pages/cart.vue

@@ -72,7 +72,7 @@
                              
                             <!-- Delete button -->
                             <span class="a-size-small">
-                              <a href="#">Delete</a>
+                              <a @click="$store.commit('removeProduct', product)" href="#">Delete</a>
                             </span>
                             &nbsp;
                             &nbsp;

+ 6 - 0
client/store/index.js

@@ -51,6 +51,12 @@ export const mutations = {
 
     let indexOfProduct = state.cart.indexOf(cartProduct)
     state.cart.splice(indexOfProduct, 1, cartProduct)
+  },
+
+  removeProduct (state, product) {
+    state.cartLength -= product.quantity
+    let indexOfProduct = state.cart.indexOf(product)
+    state.cart.splice(indexOfProduct, 1)
   }
 
 }