fix(carousel): 修复索引越界

This commit is contained in:
Sight 2022-04-20 07:12:15 +00:00 committed by Gitee
parent 5aeb4efd40
commit 3bc2245a85
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -89,8 +89,9 @@ const sub = function () {
if (childrens.value[i].props.id === active.value) {
if (i === 0) {
active.value = childrens.value[slots.length - 1].props.id;
}else{
active.value = childrens.value[i - 1].props.id;
}
active.value = childrens.value[i - 1].props.id;
break;
}
}
@ -102,8 +103,9 @@ const add = function () {
if (childrens.value[i].props.id === active.value) {
if (i === childrens.value.length - 1) {
active.value = childrens.value[0].props.id;
}else{
active.value = childrens.value[i + 1].props.id;
}
active.value = childrens.value[i + 1].props.id;
break;
}
}
@ -115,8 +117,9 @@ const autoplay = () => {
if (childrens.value[i].props.id === active.value) {
if (i === childrens.value.length - 1) {
active.value = childrens.value[0].props.id;
}else{
active.value = childrens.value[i + 1].props.id;
}
active.value = childrens.value[i + 1].props.id;
break;
}
}