内置组件:component

一,前言

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属性来决定渲染什么组件

猜你喜欢

转载自blog.csdn.net/qq_40340943/article/details/129144761