fix(carousel) 走马灯手动轮播切换到此处数据会偶现与实际不符 (#188)

This commit is contained in:
WXC-Spring 2023-05-04 04:08:37 -07:00 committed by GitHub
parent afb447d73f
commit 3e4b201e76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -1,6 +1,6 @@
<template>
<div>
<tiny-carousel height="150px" ref="carousel" :initial-index="index - 1">
<tiny-carousel height="150px" ref="carousel" :initial-index="index - 1" @change="handleChange">
<tiny-carousel-item class="carousel-item-demo" v-for="item in 8" :key="item" :name="'幻灯片 - ' + item">
<h3>{{ item }}</h3>
</tiny-carousel-item>
@ -43,6 +43,11 @@ export default {
prev() {
this.index = Math.max(this.index - 1, 0)
this.$refs.carousel.prev()
},
handleChange(newVal) {
if (newVal >= 0) {
this.index = newVal + 1
}
}
}
}