E
E
Evloshevsky Nikolay2018-08-23 17:47:39
Vue.js
Evloshevsky Nikolay, 2018-08-23 17:47:39

How to add implement tree from checkbox in VueJS?

I found such an implementation of a list-tree on Vue.

Tell me how to implement so that each item is a checkbox ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lev Roskoshin, 2018-08-23
@anjilnew

There are two ways:
1) vuex.
We take vuex, we create a tree in it, where, for example, objects are another level of the tree, and where the array is the final element with checkboxes. We create a component that receives the child tree and the path to it with props, it checks the incoming element; if it is an array, we draw checkbox elements, if it is an object, then we draw components from all branches of the tree, to which we already transfer from separate branches. You also need to remember to pass along the conditional path along which you can reach the current branch, this will be needed when you access the value associated with a specific checkbox in vuex, and here's the most interesting thing that lodash and its _.get(), _.set methods will help us () with the help of them, during the mutation of the state, we get on the way to the desired value.
2) the second option is the same, only instead of vueks infinite emits to the parent component that stores the value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question