I am currently working on developing a Tabs
component using Vue 3, similar to the one discussed in this relevant question.
<tabs>
<tab title="one">content</tab>
<tab title="two" v-if="show">content</tab> <!-- encountering issues here -->
<tab :title="t" v-for="t in ['three', 'four']">{{t}}</tab> <!-- facing challenges here as well -->
<tab title="five">content</tab>
</tabs>
Regrettably, the suggested solution does not function properly when there are dynamic Tab
s inside, such as when there is a v-if condition or when the Tab
s are rendered using a v-for
loop - it fails to work.
To further illustrate my issue, I have provided a Codesandbox demonstration with .vue
files:
https://codesandbox.io/s/sleepy-mountain-wg0bi?file=%2Fsrc%2FApp.vue
https://i.sstatic.net/EVwsr.png
I attempted to use onBeforeUpdate
similarly to onBeforeMount
, but unfortunately, that did not yield the desired results. In fact, although it did add new tabs, the tab order was altered.
The main challenge appears to be the inability to access or modify child
data from the parent component in Vue 3 (similar to how it was done with $children
in Vue 2.x). While someone recommended utilizing this.$.subtree.children
, it was strongly discouraged and did not address my issue regardless of how I implemented it.
If anyone could provide guidance on how to make the Tab
components inside Tabs
reactive and update accordingly with v-if
conditions, it would be greatly appreciated.