Last active
March 14, 2022 13:29
-
-
Save jiyuuki/e6f8f7bb67b48014223d1561119ac2fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<template> | |
<form @submit.prevent="action"> | |
<label>Your name: | |
<input name="name" required> | |
</label> | |
<button :disabled="disabled"> | |
Action | |
</button> | |
</form> | |
</template> | |
<script> | |
import { ref } from 'vue' | |
export default { | |
name: 'componentName', | |
const disabled = ref(false) | |
setup() { | |
const action = async() => { | |
disabled.value = true // disable btn to re-submits | |
// show loading after form is submitted | |
try { | |
// your api call | |
disabled.value = false // active btn before submit | |
// hide loading after form is submitted | |
} catch (error) { | |
disabled.value = false | |
// hide loading after form is submitted | |
// catch your error | |
} | |
} | |
return { | |
action, | |
disabled | |
} | |
} | |
} | |
</script> | |
<style scoped></style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i think you should return
login
or renamelogin
method toaction