一,前言
1.<component/>
是一个用于渲染动态组件或元素的“元组件”。
二,<component/>
使用
1.<component/>
功能类似于tab
组件,可用于组件的切换
2.is
属性决定了component
当前渲染的组件,is
属性可以是组件或者是字符串,当是字符串时代表组件的注册名称或者是标签名
interface DynamicComponentProps {
is: string | Component
}
<script setup>
import Foo from './Foo.vue'
import Bar from './Bar.vue'
</script>
<template>
<component :is="Math.random() > 0.5 ? Foo : Bar" />
</template>
3.component
动态组件上可以传任意参数和事件,且会被所有is
上的当前组件所接收
4.简而言之,component
就像一个容器,根据is
属性来决定渲染什么组件