Vuex $store properties not reactive when using computed property

后端 未结 6 534
孤街浪徒
孤街浪徒 2020-12-29 23:03

I have a Vuex store, which I\'m injecting into my instance:

import store from \'../store\';

const mainNav = new Vue({
  el: \'#main-nav\',
  store,
  compon         


        
6条回答
  •  被撕碎了的回忆
    2020-12-29 23:16

    This is how I solved the problem:

    I have state objects which contain other objects. I tried using Vue.set whenever there is a mutation, but it was messy and still didn't work. So I created a boolean state variable called toggleState, and provided a getter for it. Whenever a mutation changes a main state object, it also does state.stateToggle =! state.stateToggle. Anyone who cares can watch for changes to stateToggle, and do whatever is needed. In my case, it's re-building a treeview with the mutated main objects.

提交回复
热议问题