Cloud Stack Ninja

With Vue 2, we could use this.$children to get all the children components in the component slot. But with Vue 3 this is not possible anymore. And I couldn't find anything about an alternative or a workaround!

So, can anyone help with that? :)

What I want to achieve is:

To have a component with let's say name TabsView

And I want to use it like this:

<tabs-view>
  <tabs-title target="tab1">Title1</tabs-title>
  <tab-content name="tab1">...</tab-content>

  <tabs-title target="tab2">Title2</tabs-title>
  <tab-content name="tab2">...</tab-content>
<tabs-view>

And I want all the logic inside the TabsView component. So that is why I want to get the $children within it. So I can build the tabs using the values of the children components.

Because I will use the same to build tabs in different many places. And I don't want to copy the logic with refs. unless there is a way to do that with refs without moving the same logic to every place I use the component



Read more here: https://stackoverflow.com/questions/64394913/vue-js-v3-component-does-not-have-access-to-children-anymore-how-can-we-get-a

Content Attribution

This content was originally published by Hassan Ali Salem at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: