[英]State not updating on view layer after it is updated in store mutation -- Vuex
I'm using a Vuex mutation to change the value of an array called practices
.我正在使用 Vuex 突变来更改名为practices
的数组的值。 I call this mutation in a component called PracticeTree
, which includes a getter for practices
.我在一个名为PracticeTree
的组件中称这种突变,其中包括一个用于practices
的 getter。
handleNodeClick(data, other) {
this.expanded=data.namespace
this.SET_PRACTICES(data.practices)
console.log('practices as set in view layer: ')
console.log(this.practices)
},
The mutation that is called looks like:被调用的突变如下所示:
SET_PRACTICES(state, data){
Vue.set(state.practices, data)
console.log('practices as set in the store:' )
console.log(state.practices)
},
I am using Vue.set
instead of simply changing the state because I thought it might help when I saw that the state wasn't changing on the view layer - but it didn't.我正在使用Vue.set
而不是简单地更改状态,因为我认为当我看到视图层上的状态没有改变时它可能会有所帮助 - 但它没有。
Here is the output of the above functions:以下是上述函数的输出:
practices as set in the store:
store.js?0571:100 (3) [{…}, {…}, {…}, "": (...), __ob__: Observer]
PracticeTree.vue?f108:95 practices as set in view layer:
PracticeTree.vue?f108:96 []
As you can see, although the store updates the value of practices
, it doesn't change within the component.如您所见,虽然 store 更新了practices
的值,但它在组件内并没有改变。
Does anyone have any ideas as to what may be going wrong?有没有人对可能出现的问题有任何想法?
You are using the method incorrectly.您使用的方法不正确。
enter link description here在此处输入链接描述
SET_PRACTICES(state, data){
Vue.set(state, 'practices', data)
console.log('practices as set in the store:' )
console.log(state.practices)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.