vue中watch监听vuex状态的变化

vue 中使用 watch 监听 Vuex 中存储的值变化

直接使用计算属性也是一样的。store 的状态一样是响应的,变化时,computed 也会重新计算

1
2
3
4
5
6
7
8
9
10
11
12
// computed中
computed: {
monitor () {
return this.$store.state.PageId
}}

// watch中
watch: {
monitor () {
this.index = this.$store.state.PageId
}
}