Skip to content

Instantly share code, notes, and snippets.

@dobromir-hristov
Created January 27, 2019 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dobromir-hristov/6fc5b10242444c6bd0f606a8578d439e to your computer and use it in GitHub Desktop.
Save dobromir-hristov/6fc5b10242444c6bd0f606a8578d439e to your computer and use it in GitHub Desktop.
The handleClick method on the promise awaiting button
methods: {
async handleClick(event) {
try {
// set the internal loading state
this.isLoading = true;
// call the parent click listener and await it
// Using Async/Await lets us await even none promises
// pass the event so modifiers can work
await this.$listeners.click(event);
// set the isSuccess state and revert it back after this.time period
this.resetDelayed("isSuccess");
} catch (error) {
// set the hasError state and revert it back after this.time period
this.resetDelayed("hasError");
} finally {
this.isLoading = false;
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment