KoderSolutionKoderSolution LogoKoderSolution Logo
HomeArticlesTutorialsToolsRun CodeForumAI Lab
🖖

Vue

Topic Hub & Articles

Vue Intro

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Get Started

10 min

Vue Directives

10 min

Vue Events

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Forms

10 min

Vue Components

10 min

Vue Props

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Methods

10 min

Vue Computed Properties

10 min

Vue Watchers

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Class and Style Bindings

10 min

Vue Conditional Rendering

10 min

Vue List Rendering

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Template Syntax

10 min

Vue Teleport

10 min

Vue Suspense

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Transitions

10 min

Vue Mixins

10 min

Vue Custom Directives

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Plugins

10 min

Vue Slots

10 min

Vue Provide / Inject

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Dynamic Components

10 min

Vue Async Components

10 min

Composition API Intro

10 min

Recap Quiz

Gated

Milestone Assessment

ref vs reactive

10 min

Lifecycle Hooks

10 min

Dependency Injection

10 min

Recap Quiz

Gated

Milestone Assessment

Computed and Watch

10 min

Template Refs

10 min

Composable Functions

10 min

Script Setup

10 min

Progress
0%

0 / 32 Lessons

KoderSolutionKoderSolution LogoKoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Facebook PageX (Twitter) ProfileYouTube ChannelContact Support

Engineering Newsletter

Subscribe for weekly software engineering tutorials, architecture guides, and developer tool updates.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
VueVue Tutorial
Lesson

Vue Dynamic Components

10 min reading
Free Course

Vue Dynamic Components: Switching Components with <component :is>

Vue dynamic components let you swap between different components at the same mount point using the built-in <component :is="..."> element. Instead of writing long v-if / v-else-if chains, you bind :is to a variable holding the active component.

This pattern fits tabbed interfaces, multi-step checkout wizards, and configurable dashboard widgets. Each tab or step stays isolated in its own .vue file while sharing one container.

flowchart TD
    State["currentTab = shallowRef(HomeTab)"] --> Comp["component :is='currentTab'"]
    Comp --> Keep["KeepAlive Caches Inactive State"]

Preserving State with <KeepAlive>

By default, Vue unmounts and destroys the outgoing component whenever :is changes, resetting any typed form inputs inside it. Wrapping <component :is> inside <KeepAlive> caches inactive component instances in memory so users keep their state when switching tabs back and forth.

Practical SFC Dynamic Components Example

Use shallowRef() instead of ref() when storing imported component objects inside <script setup>. This tells Vue not to wrap the component definition itself in a deep reactive proxy.

<script setup>
import { shallowRef } from 'vue';
import HomeTab from './HomeTab.vue';
import ProfileTab from './ProfileTab.vue';
import SettingsTab from './SettingsTab.vue';

const tabs = [
  { name: 'Home', comp: HomeTab },
  { name: 'Profile', comp: ProfileTab },
  { name: 'Settings', comp: SettingsTab }
];

const currentTab = shallowRef(HomeTab);
</script>

<template>
  <div class="tab-system">
    <nav class="tab-buttons">
      <button
        v-for="tab in tabs"
        :key="tab.name"
        :class="{ active: currentTab === tab.comp }"
        @click="currentTab = tab.comp"
      >
        {{ tab.name }}
      </button>
    </nav>

    <KeepAlive include="ProfileTab,SettingsTab">
      <component :is="currentTab" class="tab-content" />
    </KeepAlive>
  </div>
</template>

Common Mistakes

  • Wrapping Component Definitions in ref(): Passing a .vue component to ref(HomeTab) makes Vue deeply observe the entire component object, triggering a console performance warning. Always use shallowRef().
  • Passing String Names Without Global Registration: In <script setup>, imported components are local variables, not global names. Pass the imported component object :is="HomeTab" rather than a string 'HomeTab'.
  • Caching Too Many Heavy Views: Unlimited <KeepAlive> caching can increase memory usage. Set :max="5" or use include to cache only specific component names.

Frequently Asked Questions

Which lifecycle hooks run when a <KeepAlive> component switches?

Instead of onMounted and onUnmounted running every switch, Vue invokes onActivated() when the cached component appears and onDeactivated() when it hides.

Can I pass props and events to <component :is>?

Yes. Bind props and listeners directly on <component :is="currentTab" :user-id="id" @save="onSave" /> and Vue forwards them to the active component.

Can <component :is> render standard HTML tags too?

Yes. Passing a tag string like :is="href ? 'a' : 'button'" renders a native <a> or <button> element dynamically.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Related Developer Tools & Topic Hub

Vue Topic Hub
JSON Formatter
Validate and format JSON payloads
HTML Formatter
Format HTML templates
CSS Formatter
Clean and format stylesheets
All Vue Articles
Deep-dive guides, tips & discussions
PreviousVue Provide / Inject
Continue JourneyNext: Vue Async Components

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum