Javascript

[Vue] Vuex에서 객체타입의 상태를 watch

cs09g 2019. 10. 23. 11:18
반응형

객체 타입의 state를 watch 하려면 해당 state를 업데이트할 때 처리가 필요하다.

예를들어, state를 변경할 때 다음과 같은 코드를 사용하였다면

this.$store.getters.someState.someProps = newValue;

다음과 같이 변경해준다.

this.$set(this.$store.getters.someState, someProps, newValue);

그럼 vuex가 상태의 변화를 감지할 수 있다.

 

 

객체가 지워지는 것을 감지하고자 한다면, $delete 를 사용하여 객체를 변경하자.

this.$delete(this.$store.getters.someState, someProps);

 

반응형