Skip to content

Instantly share code, notes, and snippets.

@techbysalma
Last active November 6, 2026 20:10
Show Gist options
  • Select an option

  • Save techbysalma/e6f8f7bb67b48014223d1561119ac2fa to your computer and use it in GitHub Desktop.

Select an option

Save techbysalma/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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment