Last active
July 15, 2020 01:20
-
-
Save swanson/9a47b3fbcd1112df5515c48ee7885ae8 to your computer and use it in GitHub Desktop.
This file contains 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
<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> |
This file contains 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
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