I am having trouble identifying children components in Vue.
I have this markup here:
<parent>
<child-one>
</child-one>
<child-two>
</child-two>
<child-one>
</child-one>
</parent>
The parent component is functional, so it is doing this:
render(createElement) {
return createElement('div', this.$slots.default);
},
I want to iterate over this.$children and return an Array of VNodes kind of like this:
const matchingChildren = this.$children
.filter(child => child.isChildOneType === true)
return createElement('div', {}, matchingChildren)
How do I do that?
What and where do I need to filter?
I'm pretty sure I can do it by setting a type prop on child-one, and then using this.$children.filter(child => child.$attrs.type === 'special'), but I want to filter them based on the fact they are child-one components.
I'm trying to make the example simple, but this is for tabbed pages, so I am not interested in conditional rendering. I'm trying to transform the markup into different DOM output, and I need to filter children of a specific type.
I have researched $attrs and $options as hooks that I could use, but if I use attrs, I need to add a prop to each component. I would like to avoid that since they are all of type child-one. I also can't seem to add a static property to child-one. The $options field is always empty.