我正在swiper
中使用nuxt.js
。我从他们的文档中尝试了该示例,但出现错误:
<template>
<swiper
:slides-per-view="3"
:space-between="50"
navigation
:pagination="{ clickable: true }"
:scrollbar="{ draggable: true }"
@swiper="onSwiper"
@slideChange="onSlideChange"
>
<swiper-slide>Slide 1</swiper-slide>
<swiper-slide>Slide 2</swiper-slide>
<swiper-slide>Slide 3</swiper-slide>
...
</swiper>
</template>
<script>
// import Swiper core and required components
import SwiperCore, { Navigation, Pagination, Scrollbar, A11y } from 'swiper';
// Import Swiper Vue.js components
import { Swiper, SwiperSlide } from 'swiper/vue';
// Import Swiper styles
import 'swiper/swiper.scss';
import 'swiper/components/navigation/navigation.scss';
import 'swiper/components/pagination/pagination.scss';
import 'swiper/components/scrollbar/scrollbar.scss';
// install Swiper components
SwiperCore.use([Navigation, Pagination, Scrollbar, A11y]);
// Import Swiper styles
export default {
components: {
Swiper,
SwiperSlide,
},
methods: {
onSwiper(swiper) {
console.log(swiper)
},
onSlideChange() {
console.log('slide change')
},
},
};
</script>
答案 0 :(得分:2)
Swiper docs状态:
滑动Vue.js组件仅与新的Vue.js版本3兼容。
Nuxt 2.x当前使用Vue 2,这会导致您提到的错误。一种解决方法是将Swiper的API与HTML结合使用,如以下组件所示:
get()
答案 1 :(得分:0)
如果您使用的是较新版本的nuxtjs,请将容器包装在<client-only></client-only>
中。将<no-ssr></no-ssr>
用于旧版本