Skip to content

Button

To trigger an operation.

When To Use

A button means an operation (or a series of operations). Clicking a button will trigger corresponding business logic.

In Ant Design we provide 5 types of button.

  • Primary button: indicate the main action, one primary button at most in one section.
  • Default button: indicate a series of actions without priority.
  • Dashed button: used for adding action commonly.
  • Text button: used for the most secondary action.
  • Link button: used for external links.

And 4 other properties additionally.

  • danger: used for actions of risk, like deletion or authorization.
  • ghost: used in situations with complex background, home pages usually.
  • disabled: when actions are not available.
  • loading: add loading spinner in button, avoiding multiple submits too.

Examples

Type

vue
<template>
  <a-space wrap>
    <a-button type="primary">Primary Button</a-button>
    <a-button>Default Button</a-button>
    <a-button type="dashed">Dashed Button</a-button>
    <a-button type="text">Text Button</a-button>
    <a-button type="link">Link Button</a-button>
  </a-space>
</template>

Size

vue
<template>
  <a-space wrap>
    <a-button type="primary" size="large">Large</a-button>
    <a-button type="primary">Default</a-button>
    <a-button type="primary" size="small">Small</a-button>
  </a-space>
</template>

Disabled

vue
<template>
  <a-space wrap>
    <a-button type="primary" disabled>Primary(disabled)</a-button>
    <a-button disabled>Default(disabled)</a-button>
    <a-button type="dashed" disabled>Dashed(disabled)</a-button>
    <a-button type="text" disabled>Text(disabled)</a-button>
    <a-button type="link" disabled>Link(disabled)</a-button>
  </a-space>
</template>

Loading

vue
<template>
  <a-space wrap>
    <a-button type="primary" loading>Loading</a-button>
    <a-button type="primary" size="small" loading>Loading</a-button>
    <a-button type="primary" :loading="loading" @click="enterLoading">
      Click me!
    </a-button>
  </a-space>
</template>

<script setup>
import { ref } from 'vue'

const loading = ref(false)

const enterLoading = () => {
  loading.value = true
  setTimeout(() => {
    loading.value = false
  }, 2000)
}
</script>

API

Button

PropertyDescriptionTypeDefaultVersion
disableddisabled state of buttonbooleanfalse
ghostmake background transparent and invert text and border colorsbooleanfalse
hrefredirect url of link buttonstring-
htmlTypeset the original html type of buttonstringbutton
iconset the icon component of buttonVNode | slot-
loadingset the loading status of buttonboolean |false
shapecan be set button shapedefault | circle | rounddefault
sizeset the size of buttonlarge | middle | smallmiddle
targetsame as target attribute of a, works when href is specifiedstring-
typecan be set to primary dashed link text defaultstringdefault
blockoption to fit button width to its parent widthbooleanfalse
dangerset the danger status of buttonbooleanfalse

Events

Events NameDescriptionArgumentsVersion
clickset the handler to handle click event(event) => void-

Released under the MIT License.