Last active
March 17, 2022 00:45
-
-
Save Beyarz/0f569ecca4baafeef2b1d4b72648ba0b to your computer and use it in GitHub Desktop.
StimulusJS on CDN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Stimulus</title> | |
| <script type="module"> | |
| import { | |
| Application, | |
| Controller | |
| } from "https://cdn.skypack.dev/@hotwired/stimulus"; | |
| window.Stimulus = Application.start(); | |
| Stimulus.register( | |
| "preview", | |
| class extends Controller { | |
| static targets = ["inbound", "outbound"]; | |
| setValue() { | |
| let value = this.inboundTarget.value; | |
| this.outboundTarget.innerText = value; | |
| } | |
| } | |
| ); | |
| </script> | |
| </head> | |
| <body> | |
| <div data-controller="preview"> | |
| <label>Input: </label> | |
| <input | |
| data-action="input->preview#setValue" | |
| data-preview-target="inbound" | |
| placeholder="Enter something..." | |
| value="" | |
| type="text" | |
| /> | |
| <p> | |
| You entered: | |
| <span data-preview-target="outbound"></span> | |
| </p> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment