gs-shop / vue-slick-carousel

🚥Vue Slick Carousel with True SSR Written for ⚡Faster Luxstay
https://gs-shop.github.io/vue-slick-carousel/
Other
809 stars 185 forks source link

length of undefined #75

Open Fabirm9 opened 4 years ago

Fabirm9 commented 4 years ago

I have these errors, help please.

image

My code is: image

kyuwoo-choi commented 4 years ago

please share the issue with the reproducible demo.

The28AWG commented 4 years ago

demo:

<template>
  <div>
    <vue-slick-carousel ref="slick" key="slick" v-bind="slickOptions">
      <div v-for="i in items" :key="i.id + '_' + Math.random()">
        {{ i.id }}
      </div>
    </vue-slick-carousel>
  </div>
</template>

<script>
import VueSlickCarousel from 'vue-slick-carousel'
import 'vue-slick-carousel/dist/vue-slick-carousel.css'
import 'vue-slick-carousel/dist/vue-slick-carousel-theme.css'

export default {
  layout: 'simple',
  name: 'Test',
  components: {
    VueSlickCarousel
  },

  data() {
    return {
      slickOptions: {
        autoplay: true,
        variableWidth: true,
        dots: true,
        swipeToSlide: true,
        arrows: false
      },
      items: []
    }
  },

  mounted() {
    const f = []
    for (let i = 0; i < 100; i++) {
      f.push({ id: i })
    }
    this.items = f
  }
}
</script>
The28AWG commented 4 years ago

mounted method not need. =)

The28AWG commented 4 years ago

its error with empty items/default slot

The28AWG commented 4 years ago

yep.

<vue-slick-carousel v-bind="slickOptions"> </vue-slick-carousel>

TypeError: Cannot read property 'length' of undefined at VueComponent.slideCount (vue-slick-carousel.umd.js?a7ab:10656)

kyuwoo-choi commented 4 years ago

Although the carousel is assumed to have children, It'll be better to handle the no child exception.

The28AWG commented 4 years ago

It’s just that the content may load a bit later. Specify v-if as the content is missing or not yet loaded.

fgoulhot commented 4 years ago

Hi,

I have this problem too.

Do you have a plan to provide a fix for this?

Regards

fgoulhot commented 4 years ago

Hi, For the others, I got around the bug by adding an empty div in the slot.

hari03 commented 4 years ago

Adding v-if resolved the issue, as:

<VueSlickCarousel v-bind="settings" v-if='yourVariable.length'> ... </VueSlickCarousel>

rolexta commented 4 years ago

same issue when try to use it on component

mcanvar commented 3 years ago

It's strange, I experienced this on a nuxt.js app then I register the component(despite no need to do that), it solved the issue.