Vue
vuex ) mutations 파라미터는 2개 까지 가능하다
머지?는 병합입니다
2022. 11. 22. 10:38
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>