Submit a form
Use type="submit" for the form’s primary action and show loading while the request is pending.
Components / Actions
An action button or styled link with editable variants, sizes, and a loading state.
Last changed in version 0.13.0: Add avatar groups and chips, expand the block gallery, and improve component colors, spacing, and motion.
bunx --bun @getweini/cli@latest add buttonImport the files copied by the install command, then place the component in your Vue template. The text and values in the example belong to your app; change them to fit your 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>Render a native button for actions or pass NuxtLink with as for navigation. asChild applies Button styling to one supplied child. Loading blocks repeat activation.
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.
Render an anchor through NuxtLink when a button-looking control changes pages.
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>NuxtLink owns the destination while Button supplies the Weini control treatment.
<script setup lang="ts">
import { NuxtLink } from '#components'
import Button from './components/ui/button/index.vue'
</script>
<template>
<Button :as="NuxtLink" to="/guides/getting-started">Get started</Button>
</template>Every public prop, model, event, slot, and exposed member of the installed Vue parts is listed below. “Not set” means you can leave that value out; “Required” means you must provide it. Native HTML attributes also work where the component uses a native element.
| Name | Type or signature | Default | What it does |
|---|---|---|---|
asprop | "button" | Component | "a" | undefined | "button" | Choose the HTML element or Vue component used for this control. |
asChildprop | boolean | undefined | Not set | Use one child element as the control instead of adding another wrapper. |
variantprop | "default" | "destructive" | "secondary" | "outline" | "ghost" | undefined | "default" | Choose the visual treatment for this component. |
sizeprop | "sm" | "md" | "lg" | undefined | "md" | Choose the visual size. Medium is the usual default where available. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
loadingprop | boolean | undefined | Not set | Show that an action is in progress and prevent repeat activation. |
typeprop | "button" | "submit" | "reset" | undefined | "button" | Choose the native HTML control type or action behavior. |
defaultslot | () => unknown | Required | Content shown inside Button. |
prefixslot | (() => unknown) | undefined | Optional | Content shown before the main label or value. |
suffixslot | (() => unknown) | undefined | Optional | Content shown after the main label or value. |
elementexposed | HTMLElement | null | — | Reference to the underlying HTML element. |
focusexposed | () => void | — | Move keyboard focus to this control. |
// packages/frameworks/vue/components/button/types.ts
// ------- IMPORTS -------
export type { ButtonProps } from '@getweini/vue/types'
// packages/frameworks/vue/dist/types/index.d.ts
export type { ButtonOptions, ButtonProps } from './button';
export type ControlSize = 'sm' | 'md' | 'lg';
export interface SelectOption<T = unknown> {
label: string;
value: T;
disabled?: boolean;
}
/** Application-owned copy. Bind translated strings reactively when the locale changes. */
export interface ListboxMessages {
/** Popup name when no aria-label or aria-labelledby is supplied. */
listboxLabel: string;
empty: string;
clearSelection: string;
}
export interface ListboxProps<T> {
options: readonly SelectOption<T>[];
messages: ListboxMessages;
id?: string;
disabled?: boolean;
required?: boolean;
invalid?: boolean;
name?: string;
form?: string;
placeholder?: string;
size?: ControlSize;
clearable?: boolean;
gap?: number;
/** Supply stable equality for object values. Values must be unique. */
by?: (a: T, b: T) => boolean;
/** Required for meaningful form submission of object values. */
serialize?: (value: T) => string;
}
// packages/frameworks/vue/dist/types/button.d.ts
import type { Component } from 'vue';
/** Options shared by button implementations across frameworks. */
export interface ButtonOptions<Variant extends string = string, Size extends string = string> {
variant?: Variant;
size?: Size;
disabled?: boolean;
loading?: boolean;
type?: 'button' | 'submit' | 'reset';
}
/** Vue-specific target options extend the reusable button contract. */
export interface ButtonProps<Variant extends string = 'default' | 'secondary' | 'outline' | 'ghost' | 'destructive', Size extends string = 'sm' | 'md' | 'lg'> extends ButtonOptions<Variant, Size> {
as?: 'button' | 'a' | Component;
asChild?: boolean;
}:as="NuxtLink" with to for navigation. Disabled and loading links do not navigate.