首頁  >  文章  >  web前端  >  vue3動態元件如何使用

vue3動態元件如何使用

PHPz
PHPz轉載
2023-05-12 18:49:06897瀏覽

問題:為什麼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刪除