0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

filter()사용하기

Posted at

fileter()메쏘드 사용하방법

봐도봐도 잘 이해가 되지 않는다.

store.js

export default new Vuex.Store({
  namespaced: true,
  state: {
    //data
    items: [],
  },
  getters: {},
  mutations: {
    addItem(state, item) {
      const resultItems = state.items.filter((cartItem) => {
        cartItem.id = item.id;
      });

      if (resultItems.length === 0) {
        state.items.push({
          ...item,
          qty: 1,
        });
      } else {
        resultItems[0].qty++;
      }
    },
  },
  actions: {
    addItem({ commit }, item) {
      commit("addItem", item);
    },
  },
});

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?