Carousel 轮播
示例
切换
使用 index
来控制当前显示的项目。
Index
当前是第 1 页,共 3 页
<template>
<article>
<section>
<h4>Index</h4>
<veui-number-input
v-model="index"
:min="0"
:max="items.length - 1"
/>
</section>
<section>
<veui-carousel
:datasource="items"
:index.sync="index"
/>
</section>
</article>
</template>
<script>
import { Carousel, NumberInput } from 'veui'
export default {
components: {
'veui-carousel': Carousel,
'veui-number-input': NumberInput
},
data () {
return {
items: [
{
src:
'https://ecmb.bdimg.com/public01/one-design/2b77cc4a4c5c906993c0e512f3ddaf03.jpg',
alt: 'A cute kitty looking at you with its greenish eyes.',
label: 'Cat'
},
{
src:
'https://ecmb.bdimg.com/public01/one-design/6fedc62b9221846ce5114c7447622e47.jpeg',
alt: 'A common kingfisher flying above river.',
label: 'Kingfisher'
},
{
src:
'https://ecmb.bdimg.com/public01/one-design/e1b6473c898d9e456452ee79d7533a86.jpeg',
alt: 'A white and gray dolphin in blue water.',
label: 'Dolphin'
}
],
index: 0
}
}
}
</script>
进度指示器类型
使用 indicator
属性来指定进度指示器类型。
Indicator type
当前是第 1 页,共 3 页
<template>
<article>
<section>
<h4>Indicator type</h4>
<veui-radio-group
v-model="indicator"
:items="indicators"
/>
</section>
<section>
<veui-carousel
:datasource="items"
:indicator="indicator"
/>
</section>
</article>
</template>
<script>
import { Carousel, RadioGroup } from 'veui'
export default {
components: {
'veui-carousel': Carousel,
'veui-radio-group': RadioGroup
},
data () {
return {
items: [
{
src:
'https://ecmb.bdimg.com/public01/one-design/2b77cc4a4c5c906993c0e512f3ddaf03.jpg',
alt: 'A cute kitty looking at you with its greenish eyes.',
label: 'Cat'
},
{
src:
'https://ecmb.bdimg.com/public01/one-design/6fedc62b9221846ce5114c7447622e47.jpeg',
alt: 'A common kingfisher flying above river.',
label: 'Kingfisher'
},
{
src:
'https://ecmb.bdimg.com/public01/one-design/e1b6473c898d9e456452ee79d7533a86.jpeg',
alt: 'A white and gray dolphin in blue water.',
label: 'Dolphin'
}
],
indicator: 'radio',
indicators: [
{ label: 'Radio', value: 'radio' },
{ label: 'Number', value: 'number' },
{ label: 'None', value: 'none' }
]
}
}
}
</script>
自动切换
指定 autoplay
属性来允许自动播放。
当前是第 1 页,共 3 页
还可以使用 interval
属性来指定自动播放的切换间隔时长,使用 wrap
属性来允许循环播放,以及使用 pause-on-hover
属性来时光标悬浮在指示器对应项时暂停自动播放。
<template>
<article>
<veui-carousel
:datasource="items"
autoplay
pause-on-hover
:interval="5000"
/>
</article>
</template>
<script>
import { Carousel } from 'veui'
export default {
components: {
'veui-carousel': Carousel
},
data () {
return {
items: [
{
src:
'https://ecmb.bdimg.com/public01/one-design/2b77cc4a4c5c906993c0e512f3ddaf03.jpg',
alt: 'A cute kitty looking at you with its greenish eyes.',
label: 'Cat'
},
{
src:
'https://ecmb.bdimg.com/public01/one-design/6fedc62b9221846ce5114c7447622e47.jpeg',
alt: 'A common kingfisher flying above river.',
label: 'Kingfisher'
},
{
src:
'https://ecmb.bdimg.com/public01/one-design/e1b6473c898d9e456452ee79d7533a86.jpeg',
alt: 'A white and gray dolphin in blue water.',
label: 'Dolphin'
}
],
autoplay: true,
pauseOnHover: true
}
}
}
</script>
API
属性
名称 | 类型 | 默认值 | 描述 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
datasource | Array<Object> | [] | 轮播图数据源,项目类型为:
| ||||||||||||
index | number= | 0 |
当前轮播图序号。 | ||||||||||||
indicator | string= | 'radio' | 播放进度指示器的显示模式。
| ||||||||||||
switch-trigger | string= | 'click' | 当显示单选型指示器时,触发切换的操作。
| ||||||||||||
autoplay | boolean= | false | 是否自动轮播。 | ||||||||||||
pause-on-hover | boolean= | false | 在自动轮播时,鼠标悬浮后是否暂停。 | ||||||||||||
interval | number= | 3000 | 在自动轮播时,切换间隔的毫秒数。 | ||||||||||||
wrap | boolean= | false | 是否可以循环播放。 |
插槽
名称 | 描述 |
---|---|
item | 可用来定制每个轮播项的区域。 默认内容:轮播项图片。 作用域参数为 |
事件
名称 | 描述 |
---|---|
change | 切换后触发,回调参数为 |
图标
名称 | 描述 |
---|---|
prev | 上一页。 |
next | 下一页。 |