wuyuedefeng / vue-sortable-tree

vue tree draggable, drag item sort
90 stars 21 forks source link

VueX ? #14

Open krodelabestiole opened 6 years ago

krodelabestiole commented 6 years ago

hi,

trying to use a treeData from a VueX store returns an error : Error: [vuex] Do not mutate vuex store state outside mutation handlers.

This problem is described in many places, every mutations have to be done in the store.

I managed to create a VueX compatible tree manager (sortable and nestable) using vue-draggable : https://jsfiddle.net/bestiole/pmvwhwcq/53/ I had to go through a findDeep recursive function though, that might not be the most optimized solution, but I find it clean enough. Here is another solution proposed by LinusBorg : https://forum.vuejs.org/t/nestable-interface-with-vuex-and-vue-draggable/31234/3

I still have some issue when I want to create a new children area on drag-over, and that's why I gave vue-sortable-tree a try but I probably won't keep it since it doesn't handle VueX

casbloem commented 6 years ago

You can make a set() and get() on a watcher that gets the state and sets as a mutation.