1👍
✅
You can access the slot elements in your component using the slots
parameter of the setup
function (also usable with the useSlots()
component, and it’s equivalent to this.$slots
in the option api).
Then you can know how many elements it contains.
<script setup>
const slots = useSlots()
onMounted(() => {
const defaultSlotElements = slots.default()
console.log(`My default slot has ${defaultSlotsElements.length} elements.`)
})
</script>
Source:stackexchange.com