【发布时间】:2020-04-08 18:18:20
【问题描述】:
我在这样的对象中引用 VueX getter:
computed : {
...mapGetters(['activeLayer']),
}
商店吸气剂看起来像这样:
getters : {
activeLayer : state => state.views[state.activeView].layers[state.views[state.activeView].activeLayer]
}
然后我使用手表来监控变化:
created {
var that = this;
this.$store.watch( function(state) {return state.views[state.activeView].activeLayer},
function() {
console.log(that.activeLayer); // Returns initial value
that.$store.state.views[this.$store.state.activeView].layers[this.$store.state.views[this.$store.state.activeView].activeLayer]; // Returns correct value
}
,{ deep: true } )
}
问题是当存储更改时activeLayer 不会更新为新值。
如何强制activeLayer 更新?
【问题讨论】:
-
更改
activeLayer的代码是什么? Getter 本质上是被动的,不需要强制更新。 -
@Dan 我的想法也是如此,但是当我通过 this.$store.state 等直接引用活动层时。我得到与使用 mapGetters 映射的 activeState 不同的结果。