Passing component to child <component :is> and props typings #7631
Unanswered
hidde-jan
asked this question in
Help/Questions
Replies: 1 comment 3 replies
-
I'm not sure if I fully understand your question, but I think this is what you're looking for. <script setup lang="ts">
import type { Component } from "vue";
import SimpleHeader from "./SimpleHeader.vue"
interface Props {
componentToRender: Component
}
const props = withDefaults(defineProps<Props>(), {
componentToRender: SimpleHeader
})
</script>
<template>
<p> Something here</p>
<component :is="props.componentToRender" :some-prop="1" other-prop="stringy" />
<p>Something else</p>
</template> |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I came into the following situation. I have generic component that renders a child component. However, I want to make the actual child component dynamic. Check this example:
Why not slots?
As in the example, passing around a component is very simple. If we were working with slots, then we'd need to bind to all slot props from the parent and pass them to the child component:
Of course, this is quite simple, but it is definitely more unwieldy than the first manner.
Beta Was this translation helpful? Give feedback.
All reactions