Riotjs-event-handling
提供:Dev Guides
RIOT.JS-イベント処理
refsオブジェクトを使用してHTML要素にアクセスする方法と同様の方法で、HTML要素にイベントを添付できます。 最初のステップとして、ref属性をDOM要素に追加し、タグのスクリプトブロックでthis.refを使用してそれにアクセスします。
- Attach ref -DOM要素にref属性を追加します。
<button ref = "clickButton">Click Me!</button>
- * refsオブジェクトを使用*-マウントイベントでrefsオブジェクトを使用します。 このイベントは、RIOTがカスタムタグをマウントし、refsオブジェクトにデータを入力したときに発生します。
this.on("mount", function() {
console.log("Mounting");
console.log(this.refs.username.value);
})
例
以下は完全な例です。
custom5Tag.tag
<custom5Tag>
<form>
<input ref = "username" type = "text" value = "Mahesh"/>
<input type = "submit" value = "Click Me!"/>
</form>
<script>
this.on("mount", function() {
console.log("Mounting");
console.log(this.refs.username.value);
})
</script>
</custom5Tag>
カスタム5
<html>
<head>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/riot/3.13.2/riot+compiler.min.js"></script>
</head>
<body>
<custom5Tag></custom5Tag>
<script src = "custom5Tag.tag" type = "riot/tag"></script>
<script>
riot.mount("custom5Tag");
</script>
</body>
</html>
これにより、次の結果が生成されます–