按钮组
v-btn-toggle
组件是专门针对 v-btn
构建的 v-item-group
的简单包装器。
用例
切换按钮允许您创建一个样式化的按钮组,可以在单个 v-model
下选择或切换
template script
<template>
<v-container fluid>
<v-row>
<v-col
cols="12"
sm="6"
class="py-2"
>
<p>Exclusive</p>
<v-btn-toggle v-model="toggle_exclusive">
<v-btn>
<v-icon>mdi-format-align-left</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-center</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-right</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-justify</v-icon>
</v-btn>
</v-btn-toggle>
</v-col>
<v-col
cols="12"
sm="6"
class="py-2"
>
<p>Multiple</p>
<v-btn-toggle
v-model="toggle_multiple"
dense
background-color="primary"
dark
multiple
>
<v-btn>
<v-icon>mdi-format-bold</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-italic</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-underline</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-color-fill</v-icon>
</v-btn>
</v-btn-toggle>
</v-col>
<v-col
cols="12"
sm="6"
class="py-2"
>
<p>No Options Selected</p>
<v-btn-toggle v-model="toggle_none">
<v-btn>
<v-icon>mdi-format-align-left</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-center</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-right</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-justify</v-icon>
</v-btn>
</v-btn-toggle>
</v-col>
<v-col
cols="12"
sm="6"
class="py-2"
>
<p>Mandatory</p>
<v-btn-toggle
v-model="toggle_one"
shaped
mandatory
>
<v-btn>
<v-icon>mdi-format-align-left</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-center</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-right</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-justify</v-icon>
</v-btn>
</v-btn-toggle>
</v-col>
<v-col
cols="12"
sm="6"
class="py-2"
>
<p>Text Options</p>
<v-btn-toggle
v-model="text"
tile
color="deep-purple accent-3"
group
>
<v-btn value="left">
Left
</v-btn>
<v-btn value="center">
Center
</v-btn>
<v-btn value="right">
Right
</v-btn>
<v-btn value="justify">
Justify
</v-btn>
</v-btn-toggle>
</v-col>
<v-col
cols="12"
sm="6"
class="py-2"
>
<p>Text & Icon Options</p>
<v-btn-toggle
v-model="icon"
borderless
>
<v-btn value="left">
<span class="hidden-sm-and-down">Left</span>
<v-icon right>mdi-format-align-left</v-icon>
</v-btn>
<v-btn value="center">
<span class="hidden-sm-and-down">Center</span>
<v-icon right>mdi-format-align-center</v-icon>
</v-btn>
<v-btn value="right">
<span class="hidden-sm-and-down">Right</span>
<v-icon right>mdi-format-align-right</v-icon>
</v-btn>
<v-btn value="justify">
<span class="hidden-sm-and-down">Justify</span>
<v-icon right>mdi-format-align-justify</v-icon>
</v-btn>
</v-btn-toggle>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
data () {
return {
text: 'center',
icon: 'justify',
toggle_none: null,
toggle_one: 0,
toggle_exclusive: 2,
toggle_multiple: [0, 1, 2],
}
},
}
</script>
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
示例
下面是一些简单到复杂的例子。
圆角按钮
你能够使用 rounded
属性让 VBtnToggle
变成圆角。
template script
<template>
<v-card
flat
class="py-12"
>
<v-card-text>
<v-row
align="center"
justify="center"
>
<v-col cols="12">
<p class="text-center">Rounded</p>
</v-col>
<v-btn-toggle
v-model="toggle_exclusive"
rounded
>
<v-btn>
<v-icon>mdi-format-align-left</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-center</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-right</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-justify</v-icon>
</v-btn>
</v-btn-toggle>
</v-row>
</v-card-text>
</v-card>
</template>
<script>
export default {
data () {
return {
toggle_exclusive: undefined,
}
},
}
</script>
必填项
mandatory
VBtnToggle
总是要有值
template script
<template>
<v-card
flat
class="py-12"
>
<v-card-text>
<v-row
align="center"
justify="center"
>
<v-col cols="12">
<p class="text-center">Mandatory</p>
</v-col>
<v-btn-toggle
v-model="toggle_exclusive"
mandatory
>
<v-btn>
<v-icon>mdi-format-align-left</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-center</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-right</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-justify</v-icon>
</v-btn>
</v-btn-toggle>
</v-row>
</v-card-text>
</v-card>
</template>
<script>
export default {
data () {
return {
toggle_exclusive: undefined,
}
},
}
</script>
多选
multiple
VBtnToggle
允许用户选择多个变量并返回数组值。
template script
<template>
<v-card
flat
class="py-12"
>
<v-card-text>
<v-row
align="center"
justify="center"
>
<v-col cols="12">
<p class="text-center">Multiple</p>
</v-col>
<v-btn-toggle
v-model="toggle_exclusive"
multiple
>
<v-btn>
<v-icon>mdi-format-align-left</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-center</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-right</v-icon>
</v-btn>
<v-btn>
<v-icon>mdi-format-align-justify</v-icon>
</v-btn>
</v-btn-toggle>
<v-col
cols="12"
class="text-center"
>
Model: {{ toggle_exclusive }}
</v-col>
</v-row>
</v-card-text>
</v-card>
</template>
<script>
export default {
data () {
return {
toggle_exclusive: [],
}
},
}
</script>
Alpha Theme
Complete theme experience including enhanced Vue CLI, full documentation, 5 custom components and much more!
ads by Vuetify
](https://store.vuetifyjs.com/product/alpha-theme?ref=vuetifyjs.com)
在工具栏中
与 v-toolbar
轻松集成自定义按钮
template script
<template>
<v-toolbar dense>
<v-overflow-btn
:items="dropdown_font"
label="Select font"
hide-details
class="pa-0"
></v-overflow-btn>
<template v-if="$vuetify.breakpoint.mdAndUp">
<v-divider vertical></v-divider>
<v-overflow-btn
:items="dropdown_edit"
editable
label="Select size"
hide-details
class="pa-0"
overflow
></v-overflow-btn>
<v-divider vertical></v-divider>
<v-spacer></v-spacer>
<v-btn-toggle
v-model="toggle_multiple"
color="primary"
dense
group
multiple
>
<v-btn :value="1" text>
<v-icon>mdi-format-bold</v-icon>
</v-btn>
<v-btn :value="2" text>
<v-icon>mdi-format-italic</v-icon>
</v-btn>
<v-btn :value="3" text>
<v-icon>mdi-format-underline</v-icon>
</v-btn>
<v-btn :value="4" text>
<v-icon>mdi-format-color-fill</v-icon>
</v-btn>
</v-btn-toggle>
<div class="mx-4"></div>
<v-btn-toggle
v-model="toggle_exclusive"
color="primary"
dense
group
>
<v-btn :value="1" text>
<v-icon>mdi-format-align-left</v-icon>
</v-btn>
<v-btn :value="2" text>
<v-icon>mdi-format-align-center</v-icon>
</v-btn>
<v-btn :value="3" text>
<v-icon>mdi-format-align-right</v-icon>
</v-btn>
<v-btn :value="4" text>
<v-icon>mdi-format-align-justify</v-icon>
</v-btn>
</v-btn-toggle>
</template>
</v-toolbar>
</template>
<script>
export default {
data () {
return {
dropdown_font: [
{ text: 'Arial' },
{ text: 'Calibri' },
{ text: 'Courier' },
{ text: 'Verdana' },
],
dropdown_edit: [
{ text: '100%' },
{ text: '75%' },
{ text: '50%' },
{ text: '25%' },
{ text: '0%' },
],
toggle_exclusive: 2,
toggle_multiple: [1, 2, 3],
}
},
}
</script>
选中的操作
对类似的操作进行分组,并设计自己的 WYSIWYG 组件。
template script
<template>
<v-card
max-width="400"
class="mx-auto"
>
<v-textarea
v-model="value"
auto-grow
full-width
rows="2"
></v-textarea>
<v-row
class="px-2 pb-2 ma-0"
justify="space-between"
>
<v-btn-toggle
v-model="formatting"
multiple
>
<v-btn color="white">
<v-icon>mdi-format-italic</v-icon>
</v-btn>
<v-btn color="white">
<v-icon>mdi-format-bold</v-icon>
</v-btn>
<v-btn color="white">
<v-icon>mdi-format-underline</v-icon>
</v-btn>
<v-btn color="white">
<v-row
align="center"
class="flex-column"
justify="center"
>
<v-icon class="cols 12">mdi-format-color-text</v-icon>
<v-sheet
tile
style="margin-top: -4px;"
height="4"
width="26"
color="purple"
></v-sheet>
</v-row>
</v-btn>
</v-btn-toggle>
<v-btn-toggle v-model="alignment">
<v-btn color="white">
<v-icon>mdi-format-align-center</v-icon>
</v-btn>
<v-btn color="white">
<v-icon>mdi-format-align-left</v-icon>
</v-btn>
<v-btn color="white">
<v-icon>mdi-format-align-right</v-icon>
</v-btn>
</v-btn-toggle>
</v-row>
<v-sheet
class="pa-4 text-center"
color="grey lighten-3"
tile
>
<v-row
class="mb-2"
dense
>
<v-col
v-for="n in numbers"
:key="n"
class="caption grey--text text--darken-1"
v-text="n"
></v-col>
</v-row>
<v-row dense>
<v-col
v-for="l in letters"
:key="l"
class="title grey--text font-weight-regular text--darken-2"
v-text="l"
></v-col>
</v-row>
</v-sheet>
</v-card>
</template>
<script>
export default {
data: () => ({
alignment: 1,
formatting: [],
numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
letters: 'qwertyuiop'.split(''),
value: 'Toggle button requirements.\r\rHave at least three toggle buttons in a group\rLabel buttons with text, an icon, or',
}),
}
</script>