Created
January 27, 2019 09:19
-
-
Save dobromir-hristov/6fc5b10242444c6bd0f606a8578d439e to your computer and use it in GitHub Desktop.
The handleClick method on the promise awaiting button
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
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