Motomichi Works Blog

モトミチワークスブログです。その日学習したことについて書いている日記みたいなものです。

Riot.jsその0005 イベントリスニングの開始と任意のタイミングでイベントを発生させる方法

参考にさせて頂いたページ

Riot API

vue.jsその0007 イベントリスニングの開始と任意のタイミングでイベントを発生させる方法 - MOTOMICHI WORKS BLOG

バージョン

Riot v2.0.15

riot-sample.htmlの記述内容

<body>
  <elm-example></elm-example>
  <script src="./js/core/riot+compiler.js"></script>
  <script type="riot/tag" src="./js/tags/riot-sample.tag"></script>
  <script>
    riot.mount('elm-example');
  </script>
</body>

riot-sample.tagの記述内容

<elm-example>
  <button onclick={this.runHogeEvent}>runHogeEvent();</button>
  <script>
    this.on('mount', function() {
      alert('hogeイベントのリスニングを開始します。');
      this.on('hoge', function() {
        //hogeイベントが発生したときに実行される処理
        alert('hogeイベントが発生しました。');
      });
    });
    runHogeEvent(e) {
      //hogeイベントを発生させます
      this.trigger('hoge');
    }
  </script>
</elm-example>

今回はここまで。