swiper icon indicating copy to clipboard operation
swiper copied to clipboard

Swiper Vue: Uncaught TypeError when using SwiperSlide as a wrapper

Open pmochine opened this issue 3 years ago • 7 comments

Check that this is really a bug

  • [X] I confirm

Reproduction link

https://codesandbox.io/s/swiper-navigation-vue-forked-t0r5bc?file=/src/App.vue

Bug description

Check the browser console. You get the warning and error:

Unhandled error during execution of mounted hook

Uncaught` TypeError: Cannot read properties of undefined (reading 'value') at VM54 swiper_vue.js:1229:22

This only happens, if I use my own Slide as a wrapper to add some extra content.

Expected Behavior

No error and warning. You should use the <swiper-slide> in a wrapper as well.

Actual Behavior

Swiper is not initialized.

Swiper version

^8.0.0

Platform/Target and Browser Versions

mac

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the docs.
  • [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • [X] Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • [ ] I'm willing to open a PR

pmochine avatar Apr 24 '22 10:04 pmochine

have the same issue :/

vovaleontiev avatar Jun 23 '22 00:06 vovaleontiev

Same issue using Vue 2.7.x :(

nyunyu95 avatar Jul 24 '22 06:07 nyunyu95

Same issue using Vue 2.7.x

huangbh1024 avatar Aug 19 '22 06:08 huangbh1024

I gave up with this plugin......

nyunyu95 avatar Aug 20 '22 07:08 nyunyu95

Same issue here with 2.7.x vue version

Emuzex avatar Aug 21 '22 19:08 Emuzex

Same issue using Vue 2.6.x

ezyshu avatar Sep 09 '22 02:09 ezyshu

Also having issues Vue 3 (Nuxt 3 rc.9)

Error comes from swiperRef

    onMounted(() => {
      if (!swiperRef.value) return;
      swiperRef.value.on('_slideClass', updateClasses);
      eventAttached = true;
    });

Possible workaround would be passing ref directly. However, I'm having issues with sliders rendering outside .swiper-wrapper

<template>
  <swiper-slide :swiperRef="swiper">
    <slot />
  </swiper-slide>
</template>

<script>
import { SwiperSlide, useSwiper } from 'swiper/vue'

export default {
  components: {
    SwiperSlide,
  },

  setup() {
    const swiper = useSwiper()

    return {
      swiper,
    }
  },
}
</script>

dpmango avatar Sep 15 '22 12:09 dpmango

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 21 '23 23:05 stale[bot]

Anyone figured a solution for this one ?? I'm stuck and cannot use a wrapper component

LefterisL avatar Jul 05 '23 21:07 LefterisL

Seems like adding the below will work. image Any thoughts on it ? This is inside the getChildren function in the get-children.js file.

Basically on top of check if the node is SwiperSlider or an AsyncComp check if it's a wrapper that has some SwiperSlider.

LefterisL avatar Jul 06 '23 12:07 LefterisL

Issue is closed because of outdated/irrelevant/not actual/needed more information/inactivity.

If this issue is still actual and reproducible for latest version of Swiper, please create new issue and fill the issue template correctly:

  • Clearly describe the issue including steps to reproduce when it is a bug.
  • Make sure you fill in the earliest version that you know has the issue.
  • Provide live link or JSFiddle/Codepen or website with issue

nolimits4web avatar Oct 24 '23 12:10 nolimits4web