How do I force render a dynamic component?
In this case only the last tab’s component mounts. I want them all to mount once.
const addTab = (symbol: string) => {
const id = nextTabId++;
tabs.value.push({
id,
symbol,
component: markRaw(ChartComponent),
});
activeTabId.value = id;
};
onMounted(() => {
addTab("USD");
addTab("EUR");
});
<KeepAlive>
<component
:key="activeTab?.id"
:is="activeTab?.component"
/>
</KeepAlive>
2
Answers
Since it’s a tab, only one content component is needed at once. I’ve tried a simple solution. Hope this helps.
Note:
If different components for different tab items are required, then they can be put into the tabs array with a new component property, which should trigger no issue. Dynamic props can be fed using
v-bind
attribute in the component.Demo
Not using
KeepAlive
and usev-show