svelte-swipe
svelte-swipe copied to clipboard
Showing TypeError: undefined is not iterable
[...swipeElements].forEach((element, i) => { ^
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) at onEnd (C:\Users\sapper\dev\server\server.js:714:3) at changeItem (C:\Users_sapper_\dev\server\server.js:727:3) at Timeout.changeView [as _onTimeout] (C:\Users\sapper\dev\server\server.js:731:3) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7)
same problem
this is because we are trying to import it in SSR environment, for example Sapper or SvelteKit. but if you import it like this:
import { onMount } from 'svelte';
let SwipeComponent;
let SwipeItemComponent;
const swipeConfig = {
autoplay: true,
delay: 7000,
showIndicators: true,
transitionDuration: 1000,
defaultIndex: 0
};
onMount(async () => {
const {default: swipe} = await import('svelte-swipe/src/Swipe.svelte');
const {default: swipeItem} = await import('svelte-swipe/src/SwipeItem.svelte');
SwipeComponent = swipe;
SwipeItemComponent = swipeItem;
});
and use it like this:
<div class="swipe-holder">
<svelte:component this={SwipeComponent} {...swipeConfig}>
<svelte:component this={SwipeItemComponent}>
<p>Slide1</p>
</svelte:component>
<svelte:component this={SwipeItemComponent}>
<p>Slide2</p>
</svelte:component>
<svelte:component this={SwipeItemComponent}>
<p>Slide3</p>
</svelte:component>
</svelte:component>
</div>
everything works! Including autoplay.
why an iframe been generated? Who uses iframes still?