在使用vuex

时间:2019-03-22 08:23:35

标签: javascript vue.js vuex

请检查此示例。

https://codepen.io/suedar/pen/XGyGOj

单击li后,要求div显示不显示的内容。

我知道是因为Reactivity in Depth。 我想知道在使用vuex时如何监视对象中的深层值。感谢您的回答。

1 个答案:

答案 0 :(得分:0)

Deep watch应该也可以在Vuex商店上使用。

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
    }
  }
}