Ref around slot without a wrapper element #8936
-
I need to get the list of elements inside a slot, which in vue 3 seems to only be achievable through a ref because vue does not give a way to get the list of elements in a component anymore So here is what I tried <template>
<template
ref="defaultSlot"
>
<slot />
</template>
</template>
<script setup>
import { ref } from "vue";
const defaultSlot = ref(null);
</script> But when doing that, the inner slot mounts but does not render, instead this is what is being rendered So that means vue is not using it's own template, but rather the HTML template element <template>
<div
ref="defaultSlot"
>
<slot />
</div>
</template> Wrapping it with a div does work, but it's in fact exactly what I want to avoid, I want the slot and component to maintain it's multiple root elements I also tried using Is there any way to achieve this? I was thinking of teleport but it's the same problem, without an element to teleport to it would not work |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
demo |
Beta Was this translation helpful? Give feedback.
-
@liulinboyi mentions:
Which includes Without using composition API I see the default slot now available on
|
Beta Was this translation helpful? Give feedback.
demo
Hope this helps you.