Conditionally render content in Vue parent component based on whether a slotted child component has a prop #11852
Unanswered
dbzx10299
asked this question in
Help/Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How can a block of code in a parent component template be conditionally rendered depending on whether or not a slotted child component has a prop passed to it?
Take the following code for example:
Conditional slots can be used with
$slots
in templates, i.e.v-if="$slots.default"
, but there doesn't seem to be a way to conditionally render certain content in the parent based on whether or not a slot has a prop.Inside of
<Foo/>
, note thev-if
does not work but this is the idea.This also will not work:
The only working solution is to use the
useSlots()
composable and use a render function.The thing is that vue templates are compiled to render functions, so it would seem that there is a way to access props on
$slots
.Beta Was this translation helpful? Give feedback.
All reactions