[Vuejs]-How do I monitor a deep value in object while using vuex

0👍

Deep watch should work on Vuex store as well.

import { mapState, mapMutations } from 'vuex';

export default {
  computed: {
    ...mapState([
      'allCategory'
    ])
  },
  
  methods: {
    ...mapMutations([
      'CHANGE_ALL_CATEGORY'
    ]),
    
    toggleTab(index, isShow) {
      // ...some action
      this.CHANGE_ALL_CATEGORY(allCategory);
    },
  },
  
  watch: {
    allCategory: {
      handler(val) {
        this.CHANGE_ALL_CATEGORY(val);
      },
      deep: true
    }
  }
}

Leave a comment