首页  >  文章  >  web前端  >  vue3动态组件如何使用

vue3动态组件如何使用

PHPz
PHPz转载
2023-05-12 18:49:06834浏览

问题:为什么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动态组件如何使用的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:yisu.com。如有侵权,请联系admin@php.cn删除