按钮
v-btn
组件用一 material design 主题和大量选项替代了标准的 html 按钮。任何颜色助手类都可以用来改变背景色或文本颜色。
用例
最简单的按钮包含大写文本、轻微的仰角、悬停效果和单击时的波纹效果。
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
当使用 dark 属性时,v-btn
是唯一表现不同的组件。 通常,组件使用 dark 属性来表示它们具有深色背景,并且其文本必须为白色。 虽然这对v-btn
起作用,但由于禁用状态与白色背景混合,建议仅在按钮 IS ON为彩色背景时使用属性。 如果您需要白色文本,只需添加 white—text 类。
示例
下面是一些简单到复杂的例子。
文本
文字按钮没有框影,也没有背景。只有在悬停时才会显示按钮的容器。
template
<template>
<v-row align="center">
<v-col class="text-center" cols="12" sm="4">
<div class="my-2">
<v-btn text small>Normal</v-btn>
</div>
<div class="my-2">
<v-btn text small color="primary">Primary</v-btn>
</div>
<div class="my-2">
<v-btn text small color="error">Error</v-btn>
</div>
<div class="my-2">
<v-btn text small disabled>Disabled</v-btn>
</div>
</v-col>
<v-col class="text-center" cols="12" sm="4">
<div class="my-2">
<v-btn text>Normal</v-btn>
</div>
<div class="my-2">
<v-btn text color="primary">Primary</v-btn>
</div>
<div class="my-2">
<v-btn text color="error">Error</v-btn>
</div>
<div class="my-2">
<v-btn text disabled>Disabled</v-btn>
</div>
</v-col>
<v-col class="text-center" cols="12" sm="4">
<div class="my-2">
<v-btn text large>Normal</v-btn>
</div>
<div class="my-2">
<v-btn text large color="primary">Primary</v-btn>
</div>
<div class="my-2">
<v-btn text large color="error">Error</v-btn>
</div>
<div class="my-2">
<v-btn text large disabled>Disabled</v-btn>
</div>
</v-col>
</v-row>
</template>
凸起
凸起的按钮有一个会在在点击时加重的框阴影,这是默认的样式。
template
<template>
<v-row align="center">
<v-col class="text-center" cols="12" sm="4">
<div class="my-2">
<v-btn small>Normal</v-btn>
</div>
<div class="my-2">
<v-btn small color="primary">Primary</v-btn>
</div>
<div class="my-2">
<v-btn small color="error">Error</v-btn>
</div>
<div class="my-2">
<v-btn small disabled>Disabled</v-btn>
</div>
</v-col>
<v-col class="text-center" cols="12" sm="4">
<div class="my-2">
<v-btn>Normal</v-btn>
</div>
<div class="my-2">
<v-btn color="primary">Primary</v-btn>
</div>
<div class="my-2">
<v-btn color="error">Error</v-btn>
</div>
<div class="my-2">
<v-btn disabled>Disabled</v-btn>
</div>
</v-col>
<v-col class="text-center" cols="12" sm="4">
<div class="my-2">
<v-btn large>Normal</v-btn>
</div>
<div class="my-2">
<v-btn large color="primary">Primary</v-btn>
</div>
<div class="my-2">
<v-btn large color="error">Error</v-btn>
</div>
<div class="my-2">
<v-btn large disabled>Disabled</v-btn>
</div>
</v-col>
</v-row>
</template>
凹陷
凹陷的按钮依然保持其背景色,但没有框阴影。
template
<template>
<v-row align="center">
<v-col class="text-center" cols="12" sm="4">
<div class="my-2">
<v-btn depressed small>Normal</v-btn>
</div>
<div class="my-2">
<v-btn depressed small color="primary">Primary</v-btn>
</div>
<div class="my-2">
<v-btn depressed small color="error">Error</v-btn>
</div>
<div class="my-2">
<v-btn depressed small disabled>Disabled</v-btn>
</div>
</v-col>
<v-col class="text-center" cols="12" sm="4">
<div class="my-2">
<v-btn depressed>Normal</v-btn>
</div>
<div class="my-2">
<v-btn depressed color="primary">Primary</v-btn>
</div>
<div class="my-2">
<v-btn depressed color="error">Error</v-btn>
</div>
<div class="my-2">
<v-btn depressed disabled>Disabled</v-btn>
</div>
</v-col>
<v-col class="text-center" cols="12" sm="4">
<div class="my-2">
<v-btn depressed large>Normal</v-btn>
</div>
<div class="my-2">
<v-btn depressed large color="primary">Primary</v-btn>
</div>
<div class="my-2">
<v-btn depressed large color="error">Error</v-btn>
</div>
<div class="my-2">
<v-btn depressed large disabled>Disabled</v-btn>
</div>
</v-col>
</v-row>
</template>
按钮下拉变量
按钮下拉菜单是带有额外的样式的常规选择框。
template script
<template>
<v-container id="dropdown-example">
<v-row>
<v-col cols="12" sm="4">
<p>Overflow</p>
<v-overflow-btn
class="my-2"
:items="dropdown_font"
label="Overflow Btn"
target="#dropdown-example"
></v-overflow-btn>
</v-col>
<v-col cols="12" sm="4">
<p>Segmented</p>
<v-overflow-btn
class="my-2"
:items="dropdown_icon"
label="Segmented Btn"
segmented
target="#dropdown-example"
></v-overflow-btn>
</v-col>
<v-col cols="12" sm="4">
<p>Editable</p>
<v-overflow-btn
class="my-2"
:items="dropdown_edit"
label="Editable Btn"
editable
item-value="text"
></v-overflow-btn>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
data: () => ({
dropdown_font: ['Arial', 'Calibri', 'Courier', 'Verdana'],
dropdown_icon: [
{ text: 'list', callback: () => console.log('list') },
{ text: 'favorite', callback: () => console.log('favorite') },
{ text: 'delete', callback: () => console.log('delete') },
],
dropdown_edit: [
{ text: '100%' },
{ text: '75%' },
{ text: '50%' },
{ text: '25%' },
{ text: '0%' },
],
}),
}
</script>
图标
图标可作为按钮的主要内容。
template
<template>
<v-card flat>
<v-card-text>
<v-container fluid class="pa-0">
<v-row>
<v-col cols="12">
<p>Normal</p>
</v-col>
<v-col cols="12" sm="3">
<v-btn icon color="pink">
<v-icon>mdi-heart</v-icon>
</v-btn>
</v-col>
<v-col cols="12" sm="3">
<v-btn icon color="indigo">
<v-icon>mdi-star</v-icon>
</v-btn>
</v-col>
<v-col cols="12" sm="3">
<v-btn icon color="green">
<v-icon>mdi-cached</v-icon>
</v-btn>
</v-col>
<v-col cols="12" sm="3">
<v-btn icon color="deep-orange">
<v-icon>mdi-thumb-up</v-icon>
</v-btn>
</v-col>
</v-row>
<v-row class="mt-12">
<v-col cols="12">
<p>Disabled</p>
</v-col>
<v-col cols="12" sm="3">
<v-btn icon disabled>
<v-icon>mdi-heart</v-icon>
</v-btn>
</v-col>
<v-col cols="12" sm="3">
<v-btn icon disabled>
<v-icon>mdi-star</v-icon>
</v-btn>
</v-col>
<v-col cols="12" sm="3">
<v-btn icon disabled>
<v-icon>mdi-cached</v-icon>
</v-btn>
</v-col>
<v-col cols="12" sm="3">
<v-btn icon disabled>
<v-icon>mdi-thumb-up</v-icon>
</v-btn>
</v-col>
</v-row>
</v-container>
</v-card-text>
</v-card>
</template>
浮动
浮动按钮是圆形的,通常包含一个图标。
template
<template>
<div class="text-center">
<v-btn class="mx-2" fab dark small color="primary">
<v-icon dark>mdi-minus</v-icon>
</v-btn>
<v-btn class="mx-2" fab dark small color="pink">
<v-icon dark>mdi-heart</v-icon>
</v-btn>
<v-btn class="mx-2" fab dark color="indigo">
<v-icon dark>mdi-plus</v-icon>
</v-btn>
<v-btn class="mx-2" fab dark color="teal">
<v-icon dark>mdi-format-list-bulleted-square</v-icon>
</v-btn>
<v-btn class="mx-2" fab dark large color="cyan">
<v-icon dark>mdi-pencil</v-icon>
</v-btn>
<v-btn class="mx-2" fab dark large color="purple">
<v-icon dark>mdi-android</v-icon>
</v-btn>
</div>
</template>
Light Vuetify Stickers
Stick them to your car, laptop or favorite mug. They are made from a durable vinyl with a laminate that is weather-proof against rain, sun, wind and snow, and even dishwasher safe.
ads by Vuetify
](https://store.vuetifyjs.com/product/vuetify-light-sticker?ref=vuetifyjs.com)
大小
按钮可以被设置不同的尺寸选项以适应多种方案。
template
<template>
<v-container fluid class="pa-0">
<v-row align="center">
<v-col cols="12" sm="6">
<div class="text-center">
<div class="my-2">
<v-btn x-small color="secondary" dark>Extra small Button</v-btn>
</div>
<div class="my-2">
<v-btn small color="primary" dark>Small Button</v-btn>
</div>
<div class="my-2">
<v-btn color="warning" dark>Normal Button</v-btn>
</div>
<div class="my-2">
<v-btn color="error" dark large>Large Button</v-btn>
</div>
<div class="my-2">
<v-btn x-large color="success" dark>Extra large Button</v-btn>
</div>
</div>
</v-col>
<v-col cols="12" sm="6">
<div class="text-center">
<div class="my-2">
<v-btn color="secondary" fab x-small dark>
<v-icon>mdi-television</v-icon>
</v-btn>
</div>
<div class="my-2">
<v-btn color="primary" fab small dark>
<v-icon>mdi-pencil</v-icon>
</v-btn>
</div>
<div class="my-2">
<v-btn color="warning" fab dark>
<v-icon>mdi-account-circle</v-icon>
</v-btn>
</div>
<div class="my-2">
<v-btn color="error" fab large dark>
<v-icon>mdi-alarm</v-icon>
</v-btn>
</div>
<div class="my-2">
<v-btn color="success" fab x-large dark>
<v-icon>mdi-domain</v-icon>
</v-btn>
</div>
</div>
</v-col>
</v-row>
</v-container>
</template>
轮廓
轮廓按钮从应用的当前颜色继承其边框。
template
<template>
<div class="text-center">
<v-btn class="ma-2" outlined color="indigo">Outlined Button</v-btn>
<v-btn class="ma-2" outlined fab color="teal">
<v-icon>mdi-format-list-bulleted-square</v-icon>
</v-btn>
<v-btn class="ma-2" outlined large fab color="indigo">
<v-icon>mdi-pencil</v-icon>
</v-btn>
</div>
</template>
圆角
圆形按钮的行为与常规按钮相同,但具有圆形边缘。
template
<template>
<div class="text-center">
<v-btn rounded color="primary" dark>Rounded Button</v-btn>
</div>
</template>
平铺
平铺按钮的行为与常规按钮相同,但没有边框半径。
template
<template>
<div class="text-center">
<v-btn class="ma-2" tile color="indigo" dark>Tile Button</v-btn>
<v-btn class="ma-2" tile outlined color="success">
<v-icon left>mdi-pencil</v-icon> Edit
</v-btn>
<v-btn class="ma-2" tile large color="teal" icon>
<v-icon>mdi-vuetify</v-icon>
</v-btn>
</div>
</template>
块状
块状按钮可以扩展全部可用宽度
template
<template>
<v-btn block color="secondary" dark>Block Button</v-btn>
</template>
加载器
使用加载(loading)属性,你可以通知用户有正在进行的处理。默认行为是使用一个v-progress-circular
组件,但可以对齐进行自定义。
template script style
<template>
<div class="text-center">
<v-btn
class="ma-2"
:loading="loading"
:disabled="loading"
color="secondary"
@click="loader = 'loading'"
>
Accept Terms
</v-btn>
<v-btn
:loading="loading3"
:disabled="loading3"
color="blue-grey"
class="ma-2 white--text"
@click="loader = 'loading3'"
>
Upload
<v-icon right dark>mdi-cloud-upload</v-icon>
</v-btn>
<v-btn
class="ma-2"
:loading="loading2"
:disabled="loading2"
color="success"
@click="loader = 'loading2'"
>
Custom Loader
<template v-slot:loader>
<span>Loading...</span>
</template>
</v-btn>
<v-btn
class="ma-2"
:loading="loading4"
:disabled="loading4"
color="info"
@click="loader = 'loading4'"
>
Icon Loader
<template v-slot:loader>
<span class="custom-loader">
<v-icon light>cached</v-icon>
</span>
</template>
</v-btn>
<v-btn
:loading="loading5"
:disabled="loading5"
color="blue-grey"
class="ma-2 white--text"
fab
@click="loader = 'loading5'"
>
<v-icon dark>mdi-cloud-upload</v-icon>
</v-btn>
</div>
</template>
<script>
export default {
data () {
return {
loader: null,
loading: false,
loading2: false,
loading3: false,
loading4: false,
loading5: false,
}
},
watch: {
loader () {
const l = this.loader
this[l] = !this[l]
setTimeout(() => (this[l] = false), 3000)
this.loader = null
},
},
}
</script>
<style>
.custom-loader {
animation: loader 1s infinite;
display: flex;
}
@-moz-keyframes loader {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
@-webkit-keyframes loader {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
@-o-keyframes loader {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
@keyframes loader {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
</style>