Carousel 走马灯
基础用法
使用k-carousel来定义一个走马灯。
箭头
使用 arrow 属性来控制左右箭头是否显示
垂直排列
使用 direction 属性来控制水平还是垂直排列, 默认为水平 horizontal。
间隔时间
使用 interval 属性来控制切换的间隔时间,单位是毫秒, 最小值 1200, 最大值 15000
指示器
使用 indicators 属性来控制指示器是否显示。 该属性值为 Boolean 类型。
Carousel API
Carousel 属性
| 属性名 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| defaultValue | 默认位置 | number | -------------------- | 1 |
| arrow | 箭头状态 | boolean | -------------------- | true |
| direction | 轮播方向 | string | horizontal/vertical | horizontal |
| interval | 轮播的时间间隔(min: 1200, max: 15000) | number | -------------------- | 2000 |
| autoplay | 是否自动播放 | boolean | -------------------- | true |
| indicators | 指示器状态 | boolean | -------------------- | true |
Carousel 事件
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| change | 幻灯片切换时触发 | function(currentIndex) |
Carousel 方法
| 事件名 | 说明 | 类型 |
|---|---|---|
| prev | 切换上一页触发 | function() |
| next | 切换下一页触发 | function() |
| moveTo | 移动到某一页 | function() |
vue
<template>
<k-carousel ref="kCarousel">
<div v-for="item in 5" :key="item" class="content">
{{ item }}
</div>
</k-carousel>
<k-button @click="jump">点击跳转第四页</k-button>
</template>
<script setup lang="ts">
import { ref } from 'vue';
const kCarousel = ref();
const jump = () => {
kCarousel.value.moveTo(4);
};
</style><template>
<k-carousel ref="kCarousel">
<div v-for="item in 5" :key="item" class="content">
{{ item }}
</div>
</k-carousel>
<k-button @click="jump">点击跳转第四页</k-button>
</template>
<script setup lang="ts">
import { ref } from 'vue';
const kCarousel = ref();
const jump = () => {
kCarousel.value.moveTo(4);
};
</style>