vuejs / Discussion

Vue.js discussion
166 stars 17 forks source link

Dynamic Component Instantiation #1309

Open falecci opened 7 years ago

falecci commented 7 years ago

Hi,

I have the following scenario. I have a list of categories. Whenever I click one, I make an ajax request to get its subcategories. After that, I should render another list with the subcategories, which then, of course, can have subcategories.

This could led up to something like this:

Electronics -> Computers -> Notebooks -> HP -> Accessories.

The only way I can imagine of doing this, is creating a component for the list of items, and creating a new instance whenever I click one category and have subcategories.

Is there any other way of doing it? if not, how could I create a new instance of a component everytime after I make a request?

Thanks!

FluksikartoN commented 6 years ago

Well use render function and recursion. basically you have component that renders list which list items can be clicked. so render recursively the same component which component structure is based on nested object.