Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing breaking change: Cannot easily detect empty slots from child anymore #67

Open
dorian-marchal opened this issue May 29, 2024 · 0 comments

Comments

@dorian-marchal
Copy link

In Vue 2, empty slots could easily be detected from the component using this.$slots.{name} but this is not possible anymore with Vue 3.

For example, this component renders "no slot" with Vue 2.7.16 and "slot" with Vue 3.4.23:

# App.vue
<SlotChange>
  <template v-if="false">empty</template>
</SlotChange>


# SlotChange.vue
<template>
  <div>
    <template v-if="getSlotContent($slots.default)">slot</template>
    <template v-else>no slot</template>
    <hr />
    <slot />
  </div>
</template>

<script setup>
function getSlotContent(slot) {
  return typeof slot === 'function'
    ? // Vue 3
      slot()
    : //  Vue 2
      slot
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant