[Vuex] state 배열 초기화

Rachaen·2023년 4월 12일
0

store

const titleCompetitionStore = {
  namespaced: true,
  state: () => ({
    new_nested_comments: [],
  }),
  getters: {
  },
  mutations: {
    SET_NEW_NESTED_COMMENTS_EMPTY(state) {
      state.new_nested_comments = [];
    },
  },
  actions: {
    setNestedCommentList({ commit }) {
      commit('SET_NEW_NESTED_COMMENTS_EMPTY');
    },
  },
};

export default titleCompetitionStore;

mutations에서 배열을 초기화하기위해서 빈 배열을 할당하였는데 계속해서 남아있는 문제가 있었다.

const titleCompetitionStore = {
  namespaced: true,
  state: () => ({
    new_nested_comments: [],
  }),
  getters: {
  },
  mutations: {
    SET_NEW_NESTED_COMMENTS_EMPTY(state) {
      state.new_nested_comments.splice(0);
    },
  },
  actions: {
    setNestedCommentList({ commit }) {
      commit('SET_NEW_NESTED_COMMENTS_EMPTY');
    },
  },
};

export default titleCompetitionStore;
profile
개발을 잘하자!

0개의 댓글