nuxt-swiper icon indicating copy to clipboard operation
nuxt-swiper copied to clipboard

index.js:24 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'removeEventListener')

Open Hodadisbirhan opened this issue 1 year ago • 13 comments

When I use swipper in my Nuxt3 project I got the error in the above How Could I fix It?

Hodadisbirhan avatar May 25 '23 21:05 Hodadisbirhan

I use it for https://premier911.com and I have never got that error. Can you please submit a link to reproduction 🙏🏼

cpreston321 avatar May 26 '23 00:05 cpreston321

I got the same issue while working with nuxt swiper can you please provide the solution for this one.

matrixmandeep avatar Jun 13 '23 05:06 matrixmandeep

@Hodadisbirhan @matrixmandeep I can't reproduce it. If you can please add a reproduction link 🙏🏼

cpreston321 avatar Jun 13 '23 13:06 cpreston321

I use it for https://premier911.com and I have never got that error. Can you please submit a link to reproduction 🙏🏼

image

here is the screenshot I attached where you can see the issue.

matrixmandeep avatar Jun 16 '23 06:06 matrixmandeep

the Error that I got when I tried to route to the page

Hodadisbirhan avatar Jun 16 '23 10:06 Hodadisbirhan

This issue occurs when I navigate between a page with a layout and a page without a layout (layout: false). To resolve it, I created an empty layout (just a div with a slot) and substituted the layout: false with the empty layout, successfully resolving the problem.

thomscholtens avatar Jun 28 '23 13:06 thomscholtens

Same issue when I use definePageMeta({ layout:"xxx"}), but resolve with <NuxtLayout> in template or setting layout: false

ArChiiii avatar Aug 07 '23 06:08 ArChiiii

I got the same issue but it was something related to my api calls using useFetch.

mostafaznv avatar Sep 05 '23 11:09 mostafaznv

I have the same problem. It happens to me when I switch locales with switchLocalePath (nuxt-i18n) on the same page. If the swiper component is present in both locales, then there is no error, but if the swiper component is present in one locale and not in the other, then I get the error. Does anyone know how to solve it?

mrc-bsllt avatar Nov 29 '23 15:11 mrc-bsllt

I finally solved it by migrating from nuxt-swiper to swiper.

mrc-bsllt avatar Dec 01 '23 08:12 mrc-bsllt

@mostafaznv @mrc-bsllt Guys have you managed somehow to use just swiper instead? Can you please provide the example of this?

vhovorun avatar Dec 12 '23 13:12 vhovorun

Hi @vhovorun Yes, after spending much time wrestling with nuxt-swiper, finally, I moved to swiper instead.

And this is one of my carousels:

<template>
    <swiper
        :space-between="spaceBetween"
        :slides-per-view="slidesPerView"
        :free-mode="freeMode"
        :loop="loop"
        :grab-cursor="grabCursor"
        :auto-height="autoHeight"
        :pagination="paginationOptions"
        :modules="[
            Pagination, FreeMode
        ]"
    >
        <swiper-slide v-for="(item, index) in items" :key="index">
            <slot :item="item" :index="index" />
        </swiper-slide>
    </swiper>
</template>

<script lang="ts" setup>
import {ref, computed} from 'vue'
import {Swiper, SwiperSlide} from 'swiper/vue'
import {Pagination, FreeMode} from 'swiper/modules'
import type {PaginationOptions} from 'swiper/types'
import type {CarouselProps} from '~/contracts/components/ui/carousels/Carousel'

import 'swiper/css'
import 'swiper/css/pagination'


// variables
const props = withDefaults(defineProps<CarouselProps>(), {
    spaceBetween: 16,
    slidesPerView: 1.5,
    freeMode: true,
    loop: false,
    grabCursor: false,
    autoHeight: false,
    pagination: false
})

const paginationOptions = ref<PaginationOptions>({
    enabled: props.pagination,
    clickable: false
})


// computed properties
const paddingBottom = computed(() => {
    return props.pagination ? '40px' : '0'
})
</script>

<style lang="scss" scoped>
.swiper {
    padding-bottom: v-bind(paddingBottom);


    ::v-deep(.swiper-pagination) {
        bottom: 0;

        .swiper-pagination-bullet {
            width: 24px;
            height: 4px;
            border-radius: 4px;
            background: map-get($grey, 700);
            opacity: 1;
            transition: all 300ms;
        }

        .swiper-pagination-bullet-active {
            width: 72px;
            background: map-get($secondary, 'base');
        }
    }
}
</style>

Swiper Version: ^10.3.1 Easy 🎸

mostafaznv avatar Dec 12 '23 13:12 mostafaznv

@vhovorun I updated the Nuxt swiper to use Swiper elements please check out the draft PR if you'd like to test to see if it works better than the current implementation that's used the swiper vue module. Within the draft PR contains docs and references on how to use.

cpreston321 avatar Dec 12 '23 17:12 cpreston321

@mostafaznv are you using https://swiperjs.com/vue instead of https://nuxt.com/modules/swiper?

hizbul25 avatar Jun 22 '24 06:06 hizbul25

@mostafaznv are you using https://swiperjs.com/vue instead of https://nuxt.com/modules/swiper?

Yes, I'm using swiper, not its Nuxt module. npm i swiper

mostafaznv avatar Jun 22 '24 06:06 mostafaznv