Skip to content

Button 按钮

常用的操作按钮。

基础用法

使用 typeplainround来定义按钮的样式。

<script lang="ts" setup></script>
<template>
  <p class="button-box">
    <v-button>Default</v-button>
    <v-button type="primary">Primary</v-button>
    <v-button type="success">Success</v-button>
    <v-button type="info">Info</v-button>
    <v-button type="warning">Warning</v-button>
    <v-button type="danger">Danger</v-button>
  </p>

  <p class="button-box">
    <v-button plain>Plain</v-button>
    <v-button type="primary" plain>Primary</v-button>
    <v-button type="success" plain>Success</v-button>
    <v-button type="info" plain>Info</v-button>
    <v-button type="warning" plain>Warning</v-button>
    <v-button type="danger" plain>Danger</v-button>
  </p>

  <p class="button-box">
    <v-button round>Round</v-button>
    <v-button type="primary" round>Primary</v-button>
    <v-button type="success" round>Success</v-button>
    <v-button type="info" round>Info</v-button>
    <v-button type="warning" round>Warning</v-button>
    <v-button type="danger" round>Danger</v-button>
  </p>
</template>
<style scoped>
.button-box {
  display: flex;
  gap: 8px;
}
</style>

禁用状态

你可以使用 disabled 属性来定义按钮是否被禁用。

使用 disabled 属性来控制按钮是否为禁用状态。 该属性接受一个 Boolean 类型的值。

<script setup lang="ts"></script>
<template>
  <p class="button-box">
    <v-button disabled>Default</v-button>
    <v-button disabled type="primary">Primary</v-button>
    <v-button disabled type="success">Success</v-button>
    <v-button disabled type="info">Info</v-button>
    <v-button disabled type="warning">Warning</v-button>
    <v-button disabled type="danger">Danger</v-button>
  </p>
  <p class="button-box">
    <v-button disabled plain>Plain</v-button>
    <v-button disabled plain type="primary">Primary</v-button>
    <v-button disabled plain type="success">Success</v-button>
    <v-button disabled plain type="info">Info</v-button>
    <v-button disabled plain type="warning">Warning</v-button>
    <v-button disabled plain type="danger">Danger</v-button>
  </p>
</template>
<style scoped>
.button-box {
  display: flex;
  gap: 8px;
}
</style>

按钮组

以按钮组的方式出现,常用于多项类似操作。

使用 <v-button-group> 对多个按钮分组。

<template>
  <v-button-group type="primary">
    <v-button>Previous Page</v-button>
    <v-button>Next Page</v-button>
  </v-button-group>
</template>

文字按钮

没有边框和背景色的按钮。

基础文字按钮

有背景颜色

禁用状态

<template>
  <p>基础文字按钮</p>
  <p class="button-box">
    <v-button text>Plain</v-button>
    <v-button text type="primary">Primary</v-button>
    <v-button text type="success">Success</v-button>
    <v-button text type="info">Info</v-button>
    <v-button text type="warning">Warning</v-button>
    <v-button text type="danger">Danger</v-button>
  </p>

  <p>有背景颜色</p>
  <p class="button-box">
    <v-button text bg>Plain</v-button>
    <v-button text bg type="primary">Primary</v-button>
    <v-button text bg type="success">Success</v-button>
    <v-button text bg type="info">Info</v-button>
    <v-button text bg type="warning">Warning</v-button>
    <v-button text bg type="danger">Danger</v-button>
  </p>

  <p>禁用状态</p>
  <p class="button-box">
    <v-button text disabled>Round</v-button>
    <v-button text disabled type="primary">Primary</v-button>
    <v-button text disabled type="success">Success</v-button>
    <v-button text disabled type="info">Info</v-button>
    <v-button text disabled type="warning">Warning</v-button>
    <v-button text disabled type="danger">Danger</v-button>
  </p>
</template>
<style scoped>
.button-box {
  display: flex;
  gap: 8px;
}
</style>

按钮尺寸

除了默认的大小,按钮组件还提供了几种额外的尺寸可供选择,以便适配不同的场景。

使用 size 属性额外配置尺寸,可使用 largesmall 两种值。

<script setup lang="ts"></script>
<template>
  <p class="button-box">
    <v-button size="large">Large</v-button>
    <v-button>Default</v-button>
    <v-button size="small">Small</v-button>
    <v-button size="large" type="primary">Large</v-button>
    <v-button type="primary">Default</v-button>
    <v-button size="small" type="primary">Small</v-button>
  </p>
  <p class="button-box">
    <v-button size="large" round>Large</v-button>
    <v-button round>Default</v-button>
    <v-button size="small" round>Small</v-button>
    <v-button size="large" type="primary" round>Large</v-button>
    <v-button type="primary" round>Default</v-button>
    <v-button size="small" type="primary" round>Small</v-button>
  </p>
</template>
<style scoped>
.button-box {
  display: flex;
  align-items: center;
  gap: 8px;
}
</style>

Tag

您可以自定义元素标签。例如,按钮,div,路由链接,nuxt链接。

div
a

<template>
  <div class="button-box">
    <v-button>button</v-button>
    <v-button tag="div" role="button" tabindex="0">div</v-button>
    <v-button type="primary" tag="a" href="#" target="_blank">a</v-button>
  </div>
</template>
<style scoped>
.button-box {
  display: flex;
  gap: 8px;
}
</style>

Button Attributes

属性名说明类型默认值
size尺寸'large' | 'default' | 'small'
type按钮类型'primary' | 'success' | 'warning' | 'danger' | 'info'
plain是否为朴素按钮booleanfalse
round是否为圆角按钮booleanfalse
disabled按钮是否为禁用状态booleanfalse
text是否为文字按钮booleanfalse
bg是否显示文字按钮背景颜色booleanfalse
tag自定义元素标签string | Componentbutton

Button Slots

插槽名说明
default自定义默认内容

ButtonGroup Attributes

属性名说明类型默认值
size用于控制该按钮组内按钮的大小'large' | 'default' | 'small'
type用于控制该按钮组内按钮的类型'primary' | 'success' | 'warning' | 'danger' | 'info'

ButtonGroup Slots

插槽名说明子标签
default自定义按钮组内容Button