Question presented to candidate:
"Our settings page has five tabs and the tab bar is driven by config from the server. Instead of a long v-if / v-else-if chain, a colleague used <component :is>. Explain how that works, what you can pass to :is, and what happens to a tab's state when the user switches away."
What a strong answer should cover:
<component :is="x">is a built-in placeholder; the compiler turns it intoresolveDynamicComponent(x)and renders whatever that returns.:isaccepts a component object (the usual case in<script setup>), a registered component name string, or a plain HTML tag name.- Holding a component object in state should use
shallowReformarkRaw;ref()makes it deeply reactive and Vue warns about it. - Switching
:isunmounts the old component and mounts the new one, so local state is lost unless the switch is wrapped in<KeepAlive>. - Props, attrs, events and slots passed to
<component>go to whichever component is current, so tabs need a compatible interface. - An unknown string name silently renders as a custom element, so typos do not throw.
Clarifying questions expected:
- "Should a tab keep its half-filled form when the user switches away and back?"
- "Is the list of tabs fixed at build time, or does it come from data at runtime?"
Code / implementation expected: Yes β a small tab switcher with <component :is> and a note on what switching does to state.