Skip to content

Instantly share code, notes, and snippets.

@swanson
Last active July 15, 2020 01:20
Show Gist options
  • Save swanson/9a47b3fbcd1112df5515c48ee7885ae8 to your computer and use it in GitHub Desktop.
Save swanson/9a47b3fbcd1112df5515c48ee7885ae8 to your computer and use it in GitHub Desktop.
<div data-controller="counter" data-counter-count-value="7" class="flex flex-col mt-3">
<div class="text-2xl">
The count is: <span data-counter-target="result"></span>
</div>
<div class="flex space-x-4 mt-4">
<button class="btn" data-action="counter#increment">+</button>
<button class="btn" data-action="counter#decrement">-</button>
</div>
</div>
import { Controller } from "stimulus";
export default class extends Controller {
static values = {
count: Number,
};
static targets = ["result"];
increment() {
this.countValue = this.countValue + 1;
}
decrement() {
this.countValue = this.countValue - 1;
}
countValueChanged() {
this.resultTarget.innerHTML = this.countValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment