轮播
v-carousel
组件用于在旋转计时器上显示大量的可视内容。
用例
v-carousel
组件在 v-window
的基础上进行了扩展,提供了更多针对图像显示的功能。
次要组件
v-carousel-item
:v-carousel
使用的图像容器。继承v-window-item
,且是可通过路由导航的,并使用v-img
安装在其默认插槽。
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
示例
下面是一些简单到复杂的例子。
循环
有了 cycle 属性,你可以让你的轮播每 6s(默认)自动转换到下一个。
template script
<template>
<v-carousel
cycle
height="400"
hide-delimiter-background
show-arrows-on-hover
>
<v-carousel-item
v-for="(slide, i) in slides"
:key="i"
>
<v-sheet
:color="colors[i]"
height="100%"
>
<v-row
class="fill-height"
align="center"
justify="center"
>
<div class="display-3">{{ slide }} Slide</div>
</v-row>
</v-sheet>
</v-carousel-item>
</v-carousel>
</template>
<script>
export default {
data () {
return {
colors: [
'indigo',
'warning',
'pink darken-2',
'red lighten-1',
'deep-purple accent-4',
],
slides: [
'First',
'Second',
'Third',
'Fourth',
'Fifth',
],
}
},
}
</script>
自定义过渡
v-carousel-item
组件可以使用 transition/reverse-transition 来改变过渡动画。
template script
<template>
<v-carousel>
<v-carousel-item
v-for="(item,i) in items"
:key="i"
:src="item.src"
reverse-transition="fade-transition"
transition="fade-transition"
></v-carousel-item>
</v-carousel>
</template>
<script>
export default {
data () {
return {
items: [
{
src: 'https://cdn.vuetifyjs.com/images/carousel/squirrel.jpg',
},
{
src: 'https://cdn.vuetifyjs.com/images/carousel/sky.jpg',
},
{
src: 'https://cdn.vuetifyjs.com/images/carousel/bird.jpg',
},
{
src: 'https://cdn.vuetifyjs.com/images/carousel/planet.jpg',
},
],
}
},
}
</script>
自定义分隔符
使用任何可用的图标来改变轮播的滑动分隔符。
template script
<template>
<v-card
elevation="24"
max-width="444"
class="mx-auto"
>
<v-system-bar lights-out></v-system-bar>
<v-carousel
:continuous="false"
:cycle="cycle"
:show-arrows="false"
hide-delimiter-background
delimiter-icon="mdi-minus"
height="300"
>
<v-carousel-item
v-for="(slide, i) in slides"
:key="i"
>
<v-sheet
:color="colors[i]"
height="100%"
tile
>
<v-row
class="fill-height"
align="center"
justify="center"
>
<div class="display-3">{{ slide }} Slide</div>
</v-row>
</v-sheet>
</v-carousel-item>
</v-carousel>
<v-list two-line>
<v-list-item>
<v-list-item-avatar>
<v-img src="https://cdn.vuetifyjs.com/images/john.png"></v-img>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>John Leider</v-list-item-title>
<v-list-item-subtitle>Author</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-switch
v-model="cycle"
label="Cycle Slides"
inset
></v-switch>
</v-list-item-action>
</v-list-item>
</v-list>
</v-card>
</template>
<script>
export default {
data () {
return {
colors: [
'green',
'secondary',
'yellow darken-4',
'red lighten-2',
'orange darken-1',
],
cycle: false,
slides: [
'First',
'Second',
'Third',
'Fourth',
'Fifth',
],
}
},
}
</script>
Enterprise support through Tidelift
The Tidelift Subscription is a managed open source subscription for application dependencies.
ads by Vuetify
]($a0bade116661502f.md)
隐藏控件
可以使用 :show-arrows="false"
隐藏轮播的导航控件。
template script
<template>
<v-carousel :show-arrows="false">
<v-carousel-item
v-for="(item,i) in items"
:key="i"
:src="item.src"
></v-carousel-item>
</v-carousel>
</template>
<script>
export default {
data () {
return {
items: [
{
src: 'https://cdn.vuetifyjs.com/images/carousel/squirrel.jpg',
},
{
src: 'https://cdn.vuetifyjs.com/images/carousel/sky.jpg',
},
{
src: 'https://cdn.vuetifyjs.com/images/carousel/bird.jpg',
},
{
src: 'https://cdn.vuetifyjs.com/images/carousel/planet.jpg',
},
],
}
},
}
</script>
隐藏分隔符
你可以使用 hide-delimiters
属性隐藏底部控件。
template script
<template>
<v-carousel hide-delimiters>
<v-carousel-item
v-for="(item,i) in items"
:key="i"
:src="item.src"
></v-carousel-item>
</v-carousel>
</template>
<script>
export default {
data () {
return {
items: [
{
src: 'https://cdn.vuetifyjs.com/images/carousel/squirrel.jpg',
},
{
src: 'https://cdn.vuetifyjs.com/images/carousel/sky.jpg',
},
{
src: 'https://cdn.vuetifyjs.com/images/carousel/bird.jpg',
},
{
src: 'https://cdn.vuetifyjs.com/images/carousel/planet.jpg',
},
],
}
},
}
</script>
v-model 控制
你可以用 model 控制轮播。
template script
<template>
<div>
<v-row justify="space-around">
<v-icon @click="model--">mdi-minus</v-icon>
{{ model }}
<v-icon @click="model++">mdi-plus</v-icon>
</v-row>
<v-carousel v-model="model">
<v-carousel-item
v-for="(color, i) in colors"
:key="color"
>
<v-sheet
:color="color"
height="100%"
tile
>
<v-row
class="fill-height"
align="center"
justify="center"
>
<div class="display-3">Slide {{ i + 1 }}</div>
</v-row>
</v-sheet>
</v-carousel-item>
</v-carousel>
</div>
</template>
<script>
export default {
data () {
return {
colors: [
'primary',
'secondary',
'yellow darken-2',
'red',
'orange',
],
model: 0,
}
},
}
</script>