Vue.js allows only one root element per component. In most cases, that's fine to wrap a component inside a div tag, but it can sometimes cause unexpected behavior.
For instance, when using Bootstrap, if you put a div between two elements (like <b-row> and <b-col>), the layout gets totally broken.
Many other elements in the framework need to follow a specific order, and that's why having one root element could be problematic.
Is there a way to dynamically set the root element?
To get an idea of what I'm talking about, take a look at this example.
If I have a component my-h1, like this one:
<template>
<div>
<h1>Hello world</h1>
</div>
</template>
which gets called here:
<div id="my-app">
<my-h1 />
</div>
The code above will produce:
<div id="my-app">
<div>
<h1>Hello world</h1>
</div>
</div>
How can I get this output at one place:
<div id="my-app">
<p>
<h1>Hello world</h1>
</p>
</div>
and at another place, this one:
<div id="my-app">
<a>
<h1>Hello world</h1>
</a>
</div>
(I know these tags don't make any sense, it's only for the purpose of illustration.)
I hope you see what I mean. The component should still have one root element, but it should be set to be different from the default one, with a prop or something else. :)