let's say I have a tree:
[ { name: 'asd', is_whatever: true, children: [ { name: 'asd', is_whatever: false, children: [], }, ], }, ],
The tree is stored in the module through Vuex under the key "tree" and looped through the following recursive component called the "recursive element":
<li class="recursive-item" v-for="item in tree"> {{ item.name }} <div v-if="item.is_whatever">on</div> <div v-else>off</div> <ul v-if="tree.children.length"> <recursive-item :tree="item.children"></recursive-item> </ul> </li>
Now I want to switch the item property 'is_whatever', so I am attaching a listener
<div v-if="item.is_whatever" @click="item.is_whatever = !item.is_whatever">on</div> <div v-else>off</div>
When I click on it, it works, but emits the following
"Error: [vuex] Do not mutate vuex store state outside mutation handlers." [vuex] Do not mutate vuex store state outside mutation handlers.
How can I implement it without this error? I don’t see a way to send an event or emit an event at the beginning of the tree, because it is nested and recursive, so I don’t have a path to a specific element, right?
source share