A
A
Alexey Nikolaev2019-09-25 00:40:34
Vue.js
Alexey Nikolaev, 2019-09-25 00:40:34

How to render nested structures with unknown nesting in Vue?

Goodnight.
Task: render a category tree with a visual display of nesting, and even inside the select. Top categories should denote groups of categories. A trifling, in fact, task, but on Vue I thought.
The v-if and v-for directives are not flexible by themselves. How, for example, to take into account the infinite nesting? How to do recursion? And how, for example, to render wrappers over the options of the upper categories (in the material ui component, the group is a separate type of component, inside which child options are nested)?

- category
-- category 2
--- category 3
-- category 4
- category 5

One solution seems to be JSX, which gives you the flexibility you need. But I have single-file components, and it turns out that some components will have to be done differently, moving away from the given code-style, which is not desirable.
In general, how can this be done in Vue?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2019-09-25
@Heian

a single-file component can use itself if it has a name.
More details here - https://vuejs.org/v2/guide/components-edge-cases.h...
Tree from docks - https://vuejs.org/v2/examples/tree-view.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question