Button 按钮
常用的操作按钮。
基础用法
使用 type、plain和 round来定义按钮的样式。
<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 属性额外配置尺寸,可使用 large 和 small 两种值。
<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 | 是否为朴素按钮 | boolean | false |
| round | 是否为圆角按钮 | boolean | false |
| disabled | 按钮是否为禁用状态 | boolean | false |
| text | 是否为文字按钮 | boolean | false |
| bg | 是否显示文字按钮背景颜色 | boolean | false |
| tag | 自定义元素标签 | string | Component | button |
Button Slots
| 插槽名 | 说明 |
|---|---|
| default | 自定义默认内容 |
ButtonGroup Attributes
| 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| size | 用于控制该按钮组内按钮的大小 | 'large' | 'default' | 'small' | — |
| type | 用于控制该按钮组内按钮的类型 | 'primary' | 'success' | 'warning' | 'danger' | 'info' | — |
ButtonGroup Slots
| 插槽名 | 说明 | 子标签 |
|---|---|---|
| default | 自定义按钮组内容 | Button |