Skip to content

Commit d49a510

Browse files
committed
fix: fix carousel item display error when use v-for close#2
1 parent 4103f40 commit d49a510

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

carousel/src/carousel.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,23 @@ export default defineComponent({
3434
const { pageIndex, prevPage, nextPage, setPageIndex } = usePage(modelValue.value)
3535
const { startPlay, stopPlay } = useAutoplay(nextPage, interval.value)
3636

37-
const count = useSlots().default().filter(item => typeof item.type !== 'symbol').length
37+
const getCarouselItems = () => {
38+
let carouselItems = []
39+
useSlots().default().forEach(item => {
40+
if (typeof item.type !== 'symbol') {
41+
carouselItems.push(item)
42+
} else {
43+
if (Symbol.keyFor(item.type) === 'v-fgt') {
44+
carouselItems = [...carouselItems, ...item.children]
45+
} else if(Symbol.keyFor(item.type) === 'v-txt') {
46+
console.warn('不支持文本节点,需要包裹一层元素标签,比如:item 改成 <div>item</div>')
47+
}
48+
}
49+
})
50+
return carouselItems
51+
}
52+
53+
const count = getCarouselItems().length
3854
const defaultFormattedPageIndex = formatPageIndex(pageIndex.value, count)
3955
const formattedPageIndex = ref(defaultFormattedPageIndex)
4056

0 commit comments

Comments
 (0)