How can I pass variables to my class, id or data attribute in RiotJS?
I cannot figure out how to pass my variable to class, ID or data attributes in my custom element.
<ub-item class="item cssV2 { opts.status }" id="{ opts.id }" data-link="{ opts.url }">
opts.status, opts.id, and opts.url work if I pass them in the type element <p>
, but how do I pass the variable into the attributes? HTML output includes them as strings.
+3
source to share
2 answers
Variables to be used in tags must be created using this:
<mytag>
<p class="{ myclass: show }" id="{ myid }" data-link="{ mydata }">Example</p>
<script>
this.mydata = 'foo'
this.myid = 'bar'
this.show = true
</script>
</mytag>
This will display as:
<mytag>
<p class="myclass" id="bar" data-link="foo">Example</p>
</mytag>
+3
source to share