vue3动态组件如何使用

问题:为什么vue3需要对引入的组件使用markRow?

vue2

<template>
<div>
<component :is="A"></component>
</div>
</template>

<script>
import A from &#39;./A&#39;;
export default {
name: &#39;Home&#39;,
data() {
return {}
},
components: { A },
}

vue3

<template>
<ul>
<li
v-for=&#39;(item,index) in tabList&#39;
:key=&#39;index&#39;
@click=&#39;change(index)&#39;
>
{{ item.name }}
</li>
</ul>
<keep-alive>
<component :is="currentComponent"></component>
</keep-alive>
</template>

<script setup>
import A from &#39;../components/A.vue&#39;
import B from &#39;../components/B.vue&#39;
import C from &#39;../components/C.vue&#39;
let tabList = reactive([
{name:&#39;组件A&#39;,com:markRaw(A)},
{name:&#39;组件B&#39;,com:markRaw(B)},
{name:&#39;组件C&#39;,com:markRaw(C)}
]);
let currentComponent = reactive({
com:tabList[0]
});
const change = ( idx )=>{
currentComponent = tabList[idx].com;
}

以上就是vue3动态组件如何使用的详细内容,更多请关注www.sxiaw.com其它相关文章!