Add basic Stimulus example
This commit is contained in:
commit
55388fa044
1 changed files with 24 additions and 0 deletions
24
stimulus/basic.html
Normal file
24
stimulus/basic.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
<script type="module">
|
||||
import { Application, Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"
|
||||
|
||||
window.Stimulus = Application.start()
|
||||
|
||||
Stimulus.register("hello", class extends Controller {
|
||||
static targets = [ "name", "output" ]
|
||||
|
||||
greet() {
|
||||
this.outputTarget.textContent =
|
||||
`Hello, ${this.nameTarget.value}!`
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<div data-controller="hello">
|
||||
<input data-hello-target="name" type="text">
|
||||
|
||||
<button data-action="click->hello#greet">
|
||||
Greet
|
||||
</button>
|
||||
|
||||
<span data-hello-target="output"></span>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue