<component :is> của Vue cho phép bạn render một component được quyết định lúc runtime, và <KeepAlive> cache các component đó để chúng giữ được state khi chuyển đi rồi quay lại.
Dynamic component với <component :is>
<script setup>
import { ref, shallowRef } from "vue";
import TabHome from "./TabHome.vue";
import TabProfile from "./TabProfile.vue";
const tabs = { home: TabHome, profile: TabProfile };
const current = shallowRef(TabHome); // component nào sẽ hiển thị
</script>
<template>
<button @click="current = tabs.home">Home</button>
<button @click="current = tabs.profile">Profile</button>
<component :is="current" /> <!-- render bất kỳ component nào `current` đang giữ -->
</template>
