Add StimulusJS and example controller

This commit is contained in:
Matt-Yorkley
2021-07-20 15:22:16 +01:00
parent 86500dc2aa
commit 6882201533
5 changed files with 58 additions and 192 deletions

View File

@@ -0,0 +1,18 @@
// This is what a basic Stimulus Controller looks like. To apply it to an element you can do:
// div{"data-controller": "example"}
// or:
// div{data: {controller: "example"}}
import { Controller } from "stimulus"
export default class extends Controller {
// connect() is a built-in lifecycle callback for Stimulus Controllers. It fires when the
// element is loaded on the page, and that also *includes* when some HTML is asynchronously
// injected into the DOM. This means initialization is not tied to the page load event, but
// will also happen dynamically if and when new DOM elements are added or removed.
connect() {
console.log("We're connected!")
}
}
// For more info take a look at https://stimulus.hotwired.dev/handbook/introduction