ChristophAnastasiades / Lingallery

Lingallery is a simple image gallery component for Vue.js
59 stars 22 forks source link

Getting $el undefined (if user add an invalid file type) #39

Open dev7ch opened 3 years ago

dev7ch commented 3 years ago

Thanks for the module, first :)

This error is originally caused by wrong user uplaods, ubt it d be nice if this could be catched, in development mode it breaks the size partially at lazyloading (in nuxt)

image

T loked at the code and maybe this could be sovled here.

https://github.com/ChristophAnastasiades/Lingallery/blob/75973930f56ed7c7ac33ca13960e1c6fa5101aaf/src/components/Lingallery.vue#L307

    updateCurrentImageSizes() {
      if (!this.$refs.mainImage && !this.$refs.mainImage.$el) return null
      let img =
        this.$refs.mainImage && Object.prototype.hasOwnProperty.call(this.$refs.mainImage, 'src')
          ? this.$refs.mainImage
          : this.$refs.mainImage.$el
          ? this.$refs.mainImage.$el.getElementsByTagName('img')[0]
          : null
      if (!!img) {
        this.currentImageWidth = img.naturalWidth
        this.currentImageHeight = img.naturalHeight
      }
    }