Submit a form
Use type="submit" for the form’s primary action and show loading while the request is pending.
Components / Actions
A native button with five variants, three sizes, and a loading state.
Use type="submit" for the form’s primary action and show loading while the request is pending.
Use an outline or ghost button for an action that should not compete with the primary task.
<script setup lang="ts">
import Button from './components/ui/button/Button.vue'
</script>
<template>
<Button variant="default">Save changes</Button>
<Button variant="outline" size="sm">Cancel</Button>
</template>The native submit type participates in form validation.
<script setup lang="ts">
import { ref } from 'vue'
import Button from './components/ui/button/Button.vue'
const saving = ref(false)
async function save() {
saving.value = true
try { await fetch('/api/profile', { method: 'POST' }) } finally { saving.value = false }
}
</script>
<template>
<form @submit.prevent="save">
<Button type="submit" :loading="saving">Save profile</Button>
</form>
</template>Name the consequence in the button text.
<script setup lang="ts">
import Button from './components/ui/button/Button.vue'
function removeDraft() { /* Confirm or remove the draft here. */ }
</script>
<template><Button variant="destructive" @click="removeDraft">Delete draft</Button></template>The most useful props, models, slots, events, and methods for this component.
| Name | Type | Default or requirement |
|---|---|---|
variant | default | secondary | outline | ghost | destructive | default |
size | sm | md | lg | md |
loading | boolean | false |
disabled | boolean | false |
type | button | submit | reset | button |
Native button attributes and click events pass through. Loading blocks repeat activation.