I have configured a reproduction repository:
https://github.com/devidwong/recurring-slot
Using Vue runtime-only, I am unable to use Vue.extend
(which requires template compiler)
Vue 3 is quite new to me. I decided to use it for exploration purposes. Not sure if this would work on Vue 2, but I am curious if this component should function regardless:
comment.template.html:
<div class="comment">
<slot :currentComment="comment"></slot>
<Comment v-for="reply in comment.replies" :key="reply.id" :comment="reply">
<slot :currentComment="reply"></slot>
</Comment>
</div>
usage:
comments.template.html
<Comment v-for="comment in comments" :key="comment.id" :comment="comment">
<template #default="{ currentComment }">
<div>by {{ currentComment.author }}</div>
</template>
</Comment>
for structure:
comments: [
{
id: 1,
author: 'Goodman',
replies: [
{
id: 11,
author: 'RepeatingMan',
replies: [
{
id: 111,
author: 'ExpectedMan',
replies: [
{
id: 1111,
author: 'MelodyOfFuture',
replies: []
}
]
}
]
}
]
}
]
Instead of seeing "ExpectedMan" and "MelodyOfFuture", I see "RepeatingMan" rendered three times. It seems like the second slot gets the same comment prop as the first one. I want nested comments and only define inner content once.
Is this achievable?