Vuex Tutorial #6 - Mutations

· 6년 전 · 593

Mutations https://vuex.vuejs.org/kr/guide/mutations.html

 

차일드에서 처리 할수 있지만

this.$store.state.products.forEach( product => {

  product.price -= 1;

})

 

코드가 많아지면 어디서 바꾸는지 트랙킹하기 힘들어짐.

 

mutations: {

  reducePrice: state => {

    state.products.forEach( product => {

      product.price -= 1;

    })

  }

}

 

this.$store.commit('reducePrice');

 

vue-devtools에서 트랙킹이 가능함.

 

store안에 strict : true로 하면 아웃사이드에서 수정불가 (에러남.)

 

https://github.com/iamshaunjp/vuex-playlist/tree/lesson-06

 

|

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기
🐛 버그신고