Created
March 13, 2024 21:44
-
-
Save juque/932edfb06c814894245d59166947e305 to your computer and use it in GitHub Desktop.
PHP + Turbo + Stimulus
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"> | |
<title>PHP + Turbo + Stimulus</title> | |
<script src="/javascript/turbo.es2017-umd.js"></script> | |
<script src="/javascript/stimulus.umd.js"></script> | |
<script src="/javascript/controllers/index_controller.js" data-turbolinks-track="reload"></script> | |
</head> | |
<body> | |
<h1>PHP + Turbo + Stimulus</h1> | |
<div data-controller="index"> | |
<input data-index-target="name" type="text" /> | |
<button data-action="click->index#greet"> | |
Greet | |
</button> | |
<span data-index-target="output"></span> | |
</div> | |
</body> | |
</html> |
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
const application = Stimulus.Application.start(); | |
class IndexController extends Stimulus.Controller { | |
static targets = [ "name", "output" ] | |
connect() { | |
console.log('Connected!') | |
} | |
greet() { | |
this.outputTarget.textContent = `Hello, ${this.nameTarget.value}!` | |
} | |
} | |
application.register("index", IndexController); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment