监听Vuex中的状态值

2022-04-22  本文已影响0人  安北分享

一般常用的两种监听Vuex状态值的方法:

1.用计算属性返回vuex中的状态值,再进行监听
  computed: {
    getStatus () {
      return this.$store.state.repairTabStatus
    }
  },
  watch: {
    getStatus (newVal, oldVal) {
      console.log(newVal, '监听getStatus值')
    },
  },
2.直接对vuex中的状态值进行监听
  watch: {
    '$store.state.repairTabStatus' (newVal, oldVal) {
      console.log(newVal, '监听vux值')
    }
  },
上一篇 下一篇

猜你喜欢

热点阅读