[英]Why my "Swiper" component doesn't work in a typescript react project?
So I want to use a Swiper library for react.所以我想使用 Swiper 库进行反应。 I have multiple movie elements, and I want to swipe through them.
我有多个电影元素,我想浏览它们。 I import it like this:
我这样导入它:
import Swiper from 'react-id-swiper';
And I use it that way:我这样使用它:
<div className="carousel-container">
<Swiper>
{movies.map(movie =>
<MovieItem movie={movie} key={movie.title}/>
)}
</Swiper>
</div>
So it should make a horizontal slider with movie items, but on the page it looks like this:所以它应该用电影项目制作一个水平的 slider,但在页面上它看起来像这样:
So it's like I just put all the movies inside of a common div, although when I open the code in the browser, all movies are inside of swiper div with all the classes, so I'm not sure why it doesn't work the way it should.所以就像我只是将所有电影放在一个公共 div 中一样,虽然当我在浏览器中打开代码时,所有电影都在带有所有类的 swiper div 中,所以我不确定为什么它不起作用它应该的方式。 Maybe the problem is because I use
.tsx
file?也许问题是因为我使用
.tsx
文件?
The issue is lack of css/styling.问题是缺少 css/样式。
The documentation on react-id-swiper is old. react-id-swiper的文档很旧。 According to the documentation on the main module it uses ( swiperjs ) you need to add the styling/css like so:
根据它使用的主模块 ( swiperjs ) 上的文档,您需要像这样添加样式/css:
import "swiper/css";
I've created a sandbox for you to see it working here我已经创建了一个沙箱供您查看它在这里工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.