How to create dynamic tag based on props with Vue 2

cassioscabral picture cassioscabral · Jan 19, 2017 · Viewed 26.9k times · Source

How can I make a component similar to vue-router router-link where I get the tag via props to render my template ?

<my-component tag="ul">
</my-component>

Would render:

<ul>
  anything inside my-component
</ul>

Answer

krukid picture krukid · Jun 6, 2017

You can use a built-in component element like so:

<component is="ul" class="foo" style="color:red">
  anything inside component
</component>

See: https://vuejs.org/v2/guide/components.html#Dynamic-Components