LoginSignup
0
0

More than 1 year has passed since last update.

상품추가 함수

Posted at

상품추가하는 부분때문에 개고생함
filter() 함수가 작동되지 않고
splice(index, 1)은 되는데 filter()안돼서 개고생함

store.js

   addItem(state, item) {
      const resultItems = state.items.filter((cartItem) => {
//cartItem.id = item.id; 이렇게 해서 개고생
        cartItem.id === item.id;
      });

      if (resultItems.length === 0) {
        state.items.push({
          ...item,
          qty: 1,
        });
      } else {
        resultItems[0].qty++;
      }
    },
CartList.vue
<template>
  <div>
    <!-- Cart -->
    <section class="cart bgwhite p-t-70 p-b-100">
      <template v-for="(item, index) in items">
        <tr :key="index" class="table-row">
          <td class="column-1">
            <div
              class="cart-img-product b-rad-4 o-f-hidden"
              @click="delItem(item.id)"
            >
              {{ item.id }}
              <img :src="item.image" alt="IMG-PRODUCT" />
            </div>
          </td>
        </tr>
      </template>
    </section>
  </div>
</template>

<script>
import { mapState, mapGetters } from "vuex";

export default {
  computed: {
    ...mapState(["items"]),
    ...mapGetters(["totalPrice"]),
  },
  methods: {
    delItem(id) {
      this.$store.dispatch("delItem", id);
    },
  },
};
</script>

<style></style>

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0