按钮:浮动按钮
v-btn
组件可以用作浮动按钮;它可以为应用提供最主要的操作。通过与 v-speed-dial
组件的组合使用,你可以为你的用户创建一系列的功能集。
用例
浮动按钮可以附着于材料之上,用于突显你应用中的重要操作,在大多数实例中通常使用其默认大小,而小型按钮一般用于保持其与相似大小元素之间的连续性。
template
<template>
<v-container fluid>
<v-row>
<v-col cols="12" sm="12" md="6">
<v-card>
<v-toolbar>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
</v-toolbar>
<v-card-text style="height: 300px;" class="grey lighten-5"></v-card-text>
<v-card-text style="height: 100px; position: relative">
<v-btn
absolute
dark
fab
top
right
color="pink"
>
<v-icon>mdi-plus</v-icon>
</v-btn>
</v-card-text>
</v-card>
</v-col>
<v-col cols="12" sm="12" md="6">
<v-card>
<v-toolbar extended>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<template v-slot:extension>
<v-btn
color="pink"
dark
small
absolute
bottom
left
fab
>
<v-icon>mdi-plus</v-icon>
</v-btn>
</template>
</v-toolbar>
<v-card-text style="height: 236px;" class="grey lighten-5"></v-card-text>
<v-card-text style="height: 100px; position: relative"></v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
示例
下面是一些简单到复杂的例子。
小型按钮
为了达到更好的视觉效果,我们可以使用小型按钮以适配列表的头像。
template script
<template>
<v-row>
<v-col cols="12" sm="6" offset-sm="3">
<v-card>
<v-toolbar color="light-blue" light extended>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title class="white--text">My files</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn icon>
<v-icon>mdi-magnify</v-icon>
</v-btn>
<v-btn icon>
<v-icon>mdi-view-module</v-icon>
</v-btn>
<template v-slot:extension>
<v-btn
fab
color="cyan accent-2"
bottom
left
absolute
@click="dialog = !dialog"
>
<v-icon>mdi-plus</v-icon>
</v-btn>
</template>
</v-toolbar>
<v-list two-line subheader>
<v-subheader inset>Folders</v-subheader>
<v-list-item v-for="item in items" :key="item.title" link>
<v-list-item-avatar>
<v-icon :class="[item.iconClass]">{{ item.icon }}</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{ item.title }}</v-list-item-title>
<v-list-item-subtitle>{{ item.subtitle }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon>
<v-icon color="grey lighten-1">mdi-information</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
<v-divider inset></v-divider>
<v-subheader inset>Files</v-subheader>
<v-list-item v-for="item in items2" :key="item.title" link>
<v-list-item-avatar>
<v-icon :class="[item.iconClass]">{{ item.icon }}</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{ item.title }}</v-list-item-title>
<v-list-item-subtitle>{{ item.subtitle }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon ripple>
<v-icon color="grey lighten-1">mdi-information</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
</v-list>
<v-dialog v-model="dialog" max-width="500px">
<v-card>
<v-card-text>
<v-text-field label="File name"></v-text-field>
<small class="grey--text">* This doesn't actually save.</small>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn text color="primary" @click="dialog = false">Submit</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-card>
</v-col>
</v-row>
</template>
<script>
export default {
data () {
return {
dialog: false,
items: [
{ icon: 'folder', iconClass: 'grey lighten-1 white--text', title: 'Photos', subtitle: 'Jan 9, 2014' },
{ icon: 'folder', iconClass: 'grey lighten-1 white--text', title: 'Recipes', subtitle: 'Jan 17, 2014' },
{ icon: 'folder', iconClass: 'grey lighten-1 white--text', title: 'Work', subtitle: 'Jan 28, 2014' },
],
items2: [
{ icon: 'assignment', iconClass: 'blue white--text', title: 'Vacation itinerary', subtitle: 'Jan 20, 2014' },
{ icon: 'call_to_action', iconClass: 'amber white--text', title: 'Kitchen remodel', subtitle: 'Jan 10, 2014' },
],
}
},
}
</script>
显示时的动画
首次显示时,浮动按钮应当使用一个动画效果加载到屏幕上,这里我们使用 v-fab-transition
和 v-show 来演示动画效果,你也可以使用任何 Vuetify 内置的动画或者自己定义一个。
template script
<template>
<v-container fluid>
<v-row>
<v-col cols="12" sm="12" md="6" offset-md="3">
<v-card>
<v-toolbar extended>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<template v-slot:extension>
<v-fab-transition>
<v-btn
v-show="!hidden"
color="pink"
fab
dark
small
absolute
bottom
left
>
<v-icon>mdi-plus</v-icon>
</v-btn>
</v-fab-transition>
</template>
</v-toolbar>
<v-card-text style="height: 300px;" class="grey lighten-5 text-center">
<v-btn color="primary" @click="hidden = !hidden">
{{ hidden ? 'Show' : 'Hide' }}
</v-btn>
</v-card-text>
<v-card-text style="height: 100px; position: relative">
<v-fab-transition>
<v-btn
v-show="!hidden"
color="pink"
dark
absolute
top
right
fab
>
<v-icon>mdi-plus</v-icon>
</v-btn>
</v-fab-transition>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
data: () => ({
hidden: false,
}),
}
</script>
Vuetify Epic Backpack
The Vuetify Epic Backpack is a premium backpack that has a spot for everything you travel with.
ads by Vuetify
](https://store.vuetifyjs.com/product/vuetify-epic-backpack?ref=vuetifyjs.com)
浮动按钮和 speed-dial 组件一起
v-speed-dial
组件为浮动按钮提供了强大的 api,你可以尽情定制你想要的效果。
template script style
<template>
<v-card id="create">
<v-container fluid>
<v-row class="child-flex">
<v-col cols="12" sm="6" md="4">
<v-subheader>Options</v-subheader>
<v-checkbox v-model="hover" label="Open on hover" hide-details></v-checkbox>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-subheader>FAB location</v-subheader>
<v-checkbox v-model="top" label="Top" hide-details></v-checkbox>
<v-checkbox v-model="right" label="Right" hide-details></v-checkbox>
<v-checkbox v-model="bottom" label="Bottom" hide-details></v-checkbox>
<v-checkbox v-model="left" label="Left" hide-details></v-checkbox>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-subheader>Speed dial direction</v-subheader>
<v-radio-group v-model="direction" hide-details>
<v-radio value="top" label="Top"></v-radio>
<v-radio value="right" label="Right"></v-radio>
<v-radio value="bottom" label="Bottom"></v-radio>
<v-radio value="left" label="Left"></v-radio>
</v-radio-group>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-subheader>Transition</v-subheader>
<v-radio-group v-model="transition" hide-details>
<v-radio value="slide-y-transition" label="Slide y"></v-radio>
<v-radio value="slide-y-reverse-transition" label="Slide y reverse"></v-radio>
<v-radio value="slide-x-transition" label="Slide x"></v-radio>
<v-radio value="slide-x-reverse-transition" label="Slide x reverse"></v-radio>
<v-radio value="scale-transition" label="Scale"></v-radio>
</v-radio-group>
</v-col>
</v-row>
</v-container>
<v-speed-dial
v-model="fab"
:top="top"
:bottom="bottom"
:right="right"
:left="left"
:direction="direction"
:open-on-hover="hover"
:transition="transition"
>
<template v-slot:activator>
<v-btn
v-model="fab"
color="blue darken-2"
dark
fab
>
<v-icon v-if="fab">mdi-close</v-icon>
<v-icon v-else>mdi-account-circle</v-icon>
</v-btn>
</template>
<v-btn
fab
dark
small
color="green"
>
<v-icon>mdi-pencil</v-icon>
</v-btn>
<v-btn
fab
dark
small
color="indigo"
>
<v-icon>mdi-plus</v-icon>
</v-btn>
<v-btn
fab
dark
small
color="red"
>
<v-icon>mdi-delete</v-icon>
</v-btn>
</v-speed-dial>
</v-card>
</template>
<script>
export default {
data: () => ({
direction: 'top',
fab: false,
fling: false,
hover: false,
tabs: null,
top: false,
right: true,
bottom: true,
left: false,
transition: 'slide-y-reverse-transition',
}),
computed: {
activeFab () {
switch (this.tabs) {
case 'one': return { class: 'purple', icon: 'account_circle' }
case 'two': return { class: 'red', icon: 'edit' }
case 'three': return { class: 'green', icon: 'keyboard_arrow_up' }
default: return {}
}
},
},
watch: {
top (val) {
this.bottom = !val
},
right (val) {
this.left = !val
},
bottom (val) {
this.top = !val
},
left (val) {
this.right = !val
},
},
}
</script>
<style>
/* This is for documentation purposes and will not be needed in your application */
#create .v-speed-dial {
position: absolute;
}
#create .v-btn--floating {
position: relative;
}
</style>
横向屏幕切换
当你的按钮需要改变默认的操作时,推荐使用一个过渡效果来彰显它的变化(如下进行标签页切换时,给悬浮响应按钮一个过渡动画)。我们是通过绑定 key
属性到数据块来正确地发送响应变化信号至 Vue 过渡系统。当你使用自定义过渡效果时,请确保已经设置mode
属性为 out-in。
template script style
<template>
<v-card id="lateral">
<v-toolbar
dark
tabs
flat
color="indigo"
>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title>Page title</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn icon>
<v-icon>mdi-magnify</v-icon>
</v-btn>
<v-btn icon>
<v-icon>mdi-dots-vertical</v-icon>
</v-btn>
<template v-slot:extension>
<v-tabs
v-model="tabs"
align-with-title
>
<v-tab href="#one">Item One</v-tab>
<v-tab href="#two">Item Two</v-tab>
<v-tab href="#three">Item Three</v-tab>
<v-tabs-slider color="pink"></v-tabs-slider>
</v-tabs>
</template>
</v-toolbar>
<v-card-text>
<v-tabs-items v-model="tabs">
<v-tab-item
v-for="content in ['one', 'two', 'three']"
:key="content"
:value="content"
>
<v-card
height="200px"
flat
>
</v-card>
</v-tab-item>
</v-tabs-items>
</v-card-text>
<v-fab-transition>
<v-btn
:key="activeFab.icon"
:color="activeFab.color"
fab
large
dark
bottom
left
class="v-btn--example"
>
<v-icon>{{ activeFab.icon }}</v-icon>
</v-btn>
</v-fab-transition>
</v-card>
</template>
<script>
export default {
data: () => ({
fab: false,
hidden: false,
tabs: null,
}),
computed: {
activeFab () {
switch (this.tabs) {
case 'one': return { color: 'success', icon: 'share' }
case 'two': return { color: 'red', icon: 'edit' }
case 'three': return { color: 'green', icon: 'keyboard_arrow_up' }
default: return {}
}
},
},
}
</script>
<style>
/* This is for documentation purposes and will not be needed in your application */
#lateral .v-btn--example {
bottom: 0;
position: absolute;
margin: 0 0 16px 16px;
}
</style>