Skip to content

Instantly share code, notes, and snippets.

@jiyuuki
Last active March 14, 2022 13:29
Show Gist options
  • Save jiyuuki/e6f8f7bb67b48014223d1561119ac2fa to your computer and use it in GitHub Desktop.
Save jiyuuki/e6f8f7bb67b48014223d1561119ac2fa to your computer and use it in GitHub Desktop.
<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>
@khofaai
Copy link

khofaai commented Mar 4, 2022

i think you should return login or rename login method to action

@jiyuuki
Copy link
Author

jiyuuki commented Mar 9, 2022

@khofaai 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment