Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

successdav's avatar

Alternative to this.$children in vue

in vue 2 I can to this

<tabs>
	<tab name="some-title"></tab>
	<tab name="some-other-title"> </tab>
</tabs>

and on the tabs componenet I can access all children component with this.$children

		created () {
			this.tabs = this.$children
		},

With this I could create a tab component but now in Vue 3, this.$children is no longer supported and refs is not recommended in the docs.

You know a way to make this work? Thanks.

0 likes
2 replies
successdav's avatar

@vincent15000 I have tried using refs and I can only get hold of children that are insided the component where it is created. e.g.

//inside the tabs.vue component
<template>
	<tab ref="tab"></tab>
    <tab ref="tab"></tab>
</template>

In the code above, vue refs will return the two tab children but when I use this component elsewhere like

<tabs>
		<tab ref="tab">Tab One content</tab>
        <tab ref="tab">Tab One content</tab>
</tabs>

In this second example, vue refs will return undefined.

Please or to participate in this conversation.