Question
How can I set a timeout between clicks which will toggle the disabled attribute in a button?
Due to API restrictions, queries are limited. So to prevent users from just sitting there clicking too fast and not seeing the page refresh, I want to force a time between clicks. The proposed solution that I have is to pass in the disabled
attribute to the button after it is clicked, then remove that in 5 seconds to allow the user to click again.
Code
Working demo on CodePen
HTML
<button
v-on:click="GetTacos"
class="mdl-button mdl-js-button mdl-button--raised mdl-button--accent"
id="tacoBtn"
>new recipe</button>
JS - Babel
I originally thought that while it is disabled the following class should be removed mdl-button--accent
. But when experimenting with the code, if you simply pass in the disabled
attribute, the button changes style too.
Background
I have found other solutions but they libraries like jQuery
Those will not work for my specific use
I also looked at passing in disabled attribute but most of those solutions were for reactjs
Not sure how to translate those solutions to my project though.