You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to integrate Embla Carousel in a Vue (v3.5.13) component (composition api) and I have an issue when using a v-if on the results ref variable in the parent/root div. Without the v-if="isNotEmpty(results)" control Embla work fine.
Have you guys a suggestion to make it work and keeping the v-if on top?
Thanks.
If applicable, which variants of Embla Carousel are relevant to this question?
embla-carousel (Core)
embla-carousel-react
embla-carousel-vue
embla-carousel-svelte
embla-carousel-autoplay
embla-carousel-auto-scroll
embla-carousel-solid
embla-carousel-auto-height
embla-carousel-class-names
embla-carousel-fade
embla-carousel-docs (Documentation)
embla-carousel-docs (Generator)
Additional information
A simplified version of the component:
<scriptsetuplang="ts">import{ref}from'vue'importemblaCarouselVuefrom'embla-carousel-vue'importclientfrom'@/client'import{isNotEmpty}from'@/helpers'importtype{AxiosError}from'axios'importtype{EmblaOptionsType}from'embla-carousel'importtype{FastResultsResponse,MessageErrorResponse}from'@/types'defineOptions({inheritAttrs: false})constprops=withDefaults(defineProps<{route: stringtitle?: string}>(),{title: undefined,})constresults=ref<FastResultsResponse|null>(null)consterrorMsg=ref<string>('')constisLoading=ref<boolean>(false)constoptions: EmblaOptionsType={align: 'start',dragFree: true,loop: false}const[emblaRef]=emblaCarouselVue(options)asyncfunctionfetchData(){isLoading.value=truetry{const{ data }=awaitclient.post<FastResultsResponse>(props.route)results.value=isNotEmpty(data) ? data : null}catch(e){consterr=easAxiosErrorerrorMsg.value=(err.response?.dataasMessageErrorResponse).messageresults.value=null}finally{isLoading.value=false}}fetchData()</script><template><divv-if="isNotEmpty(results)"
:class="$attrs.class"
><divclass="embla p-2 overflow-hidden"
ref="emblaRef"
><divclass="embla__container grid grid-cols-[repeat(auto-fill,14rem)] grid-flow-col gap-3 touch-pan-y"><divv-for="(result, index) in results"
:key="`slide-${index}`"
class="embla__slide"
>
Slide {{ index }}
</div></div></div></div></template>
help wantedFeel free to help outquestionQuestion about how to achieve somethingvueIssue is related to Vue
1 participant
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
Hello,
I'm trying to integrate Embla Carousel in a Vue (v3.5.13) component (composition api) and I have an issue when using a v-if on the results ref variable in the parent/root div. Without the
v-if="isNotEmpty(results)"
control Embla work fine.Have you guys a suggestion to make it work and keeping the v-if on top?
Thanks.
If applicable, which variants of Embla Carousel are relevant to this question?
Additional information
A simplified version of the component:
CodeSandbox example
No response
Beta Was this translation helpful? Give feedback.
All reactions