Is it feasible to utilize Vue's <component>
element to selectively display a component or nothing at all?
Let's consider the following scenario:
<component :is="hasTooltip ? 'CustomTooltip' : 'div'">
<div>Hover over me!</div>
</component>
In this example, we are showing a CustomTooltip
component when the value of hasTooltip
is true, otherwise we are displaying a regular div. Is there a way to display a fragment instead of this div (similar to React's <>
fragment) that will be removed in the browser? How can this be achieved? I am using Vue 2.0.
Simply rendering the component based on conditions will not suffice as we still want the "Hover over me!" text to appear.