본문 바로가기

Vue

vuex ) mutations 파라미터는 2개 까지 가능하다

 

mutations: {
    removeOneItem(state, payload) {
      localStorage.removeItem(payload.todoItem.item);
      state.todoItems.splice(payload.index, 1);
    },
}

 

 

mutations 의 파라미터는 2개 이상이 되면 안된다

하위 컴포넌트에서 2개 이상의 파라미터를 넘기려면 아래처럼 객체화 해서 vuex로 전달하고

payload.속성  으로  접근해야 정상적으로 실행이 된다.

 

<script>
export default {
  methods: {
    removeTodo(todoItem, index) {
      this.$store.commit('removeOneItem', { todoItem, index } );
    }
}
</script>

 

위는 아래 코드의 객체 만드는 과정이 축약된 문법이다.

<script>
export default {
  methods: {
    removeTodo(todoItem, index) {
    const obj = {
        todoItem: todoItem,
        index: index
        }
      this.$store.commit('removeOneItem', obj );
    }
}
</script>

'Vue' 카테고리의 다른 글

Vuex 기술 요소(state, getters, mutations, actions)  (0) 2023.03.19
[Vue2] Vuex 에 관하여  (0) 2023.03.19
[Vue 3] ref()란?  (0) 2023.03.19
[VUE 3] Composition API 란?  (0) 2022.12.24
Vue 2 와 Vue3 의 차이  (0) 2022.12.24