Is it possible to separate javascript code from a tag file in Riot Js?

I would like to know if it is possible to do something like:

<todo>
    <div class="greetings">Hello, world!</div>

    <script src="/path/to/my/file.js"></script>
</todo>

The tag will save the view (html), while the js code will remain in another file:

  • todo.tag (html / css)
  • todo.js
+4
source share
3 answers

To give an alternative to the solution mixin, here is another way to share your markup with your logic.

Plunker ( ). , . <script>todoTag.call(this, this.opts);</script>. todoTag . , .

:

todo.tag.html:

<todo>
    <!-- your markup -->
    <script>todoTag.call(this, this.opts);</script>
</todo>

todo.tag.js:

function todoTag(opts) {
    // your logic
}
+5

, , js mixins. , - :

<dropdown>

    <select>...</select>

    <!-- more html code here -->

    this.mixin(Dropdown);

</dropdown>

Dropdown dropdown.js dropdown.tag.

, .

+2

js- , js, :

<dropdown>

    <!-- html code -->

    <script>new Dropdown(this)</script>

</dropdown>

function Dropdown(tag) {
    // constructor code
}

Dropdown.prototype = { ... }

0

Source: https://habr.com/ru/post/1624029/


All Articles