我试图使用swiper(6.8.4)与SSR,但与CSS建设使以下问题:
参考错误:未定义文档
没有swiper CSS,构建成功,但没有swiper功能工作...
下面是我代码:
import React from 'react'
import { Swiper, SwiperSlide } from 'swiper/react'
import SwiperCore, { Navigation, Pagination, Mousewheel, Keyboard, Autoplay, Virtual, A11y } from 'swiper'
// swiper bundle styles
import 'swiper/swiper-bundle.min.css'
// swiper core styles
import 'swiper/swiper.min.css'
// modules styles
import 'swiper/components/navigation/navigation.min.css'
import 'swiper/components/pagination/pagination.min.css'
// install Swiper modules
SwiperCore.use([Navigation, Pagination, Mousewheel, Keyboard, Autoplay, Virtual, A11y])
const Carousel = ({ data, renderSlide }) => {
return (
<Swiper
mousewheel
keyboard
className="mySwiper"
slidesPerColumnFill="row"
touchStartPreventDefault={false}
watchOverflow
>
<div className="swiper-container">
<SwiperSlide>
<img src="https://www.imperial-library.info/sites/default/files/Fonts_Alphabets_Magic_Script.png" />{" "}
</SwiperSlide>
<SwiperSlide>
<img src="https://www.imperial-library.info/sites/default/files/Fonts_Alphabets_Magic_Script.png" />{" "}
</SwiperSlide>
<SwiperSlide>
<img src="https://www.imperial-library.info/sites/default/files/Fonts_Alphabets_Magic_Script.png" />{" "}
</SwiperSlide>
</div>
</Swiper>
)
}
export default Carousel
3条答案
按热度按时间00jrzges1#
你需要这样使用……
参考链接:https://swiperjs.com/react#installation
mf98qq942#
更新你的swiper版本到
"swiper": "^7.4.1"
,然后使用下面的代码。n3h0vuf23#