我在使用最新版本的 Swiper 时也遇到了同样的问题。它在我之前的项目中有效,但现在不起作用。连那个版本都没有。最新版本也试过了。
这是我的代码。
// Import Swiper React components
import { Swiper, SwiperSlide } from "swiper/react";
// Import Swiper styles
import "swiper/css";
const App = () => {
return (
<Swiper
spaceBetween={50}
slidesPerView={3}
onSlideChange={() => console.log("slide change")}
onSwiper={(swiper) => console.log(swiper)}
>
<SwiperSlide>Slide 1</SwiperSlide>
<SwiperSlide>Slide 2</SwiperSlide>
<SwiperSlide>Slide 3</SwiperSlide>
<SwiperSlide>Slide 4</SwiperSlide>
...
</Swiper>
);
};
export default App;
Run Code Online (Sandbox Code Playgroud)
每当我运行代码时,它都会显示“找不到模块:无法解析‘swiper/react’”。