HTML elements as components
Standard HTML elements can be used as riot components in the page body with the addition of the is
attribute.
<ul is="my-list"></ul>
This provides users with an alternative that can provide greater compatibility with css frameworks. The tags are treated like any other custom component.
riot.mount('my-list')
will mount the ul
element shown above as if it were <my-list></my-list>
Note that you can use also an expression in the is
attribute and riot will be able to render dynamically also different tags on the same DOM node
<my-component>
<!-- dynamic component -->
<div is={ animal }></div>
<button onclick={ switchComponent }>
Switch
</button>
<script>
export default {
animal: 'dog',
switchComponent() {
// riot will render the <cat> component
// replacing <dog>
this.animal = 'cat'
this.update()
}
}
</script>
</my-component>
Note that when using the is
attribute, the tag name should be rendered in all lowercase, regardless of how it’s defined.
<MyComponent></MyComponent> <!-- Correct -->
<div is="mycomponent"></div> <!-- Also Correct -->
<div is="MyComponent"></div> <!-- Incorrect -->
<script>
riot.mount('MyComponent');
</script>
Note that you can use is
attribute with any HTML tags, but not with template
tag.