简体   繁体   English

为什么我的“Swiper”组件在 typescript 反应项目中不起作用?

[英]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.

相关问题 为什么引导手风琴组件在我的反应项目中不起作用? - Why bootstrap accordion component doesn't work in my react project? 为什么 toFixed() 在我的 React 功能组件中不起作用? - why doesn't toFixed() work in my React functional component? 我的React组件计时器不起作用 - My react component timer doesn't work 为什么 React 组件更新不起作用 - Why the React component update doesn't work React.js,为什么我的类组件不重新渲染元素,但是功能组件可以工作? - React.js, why my class component doesn't rerender the element, but functional component can work? 为什么我在 React 中的 clearInterval 不起作用? - Why my clearInterval in React doesn't work? Swiper Js 垂直循环无法正常工作以进行反应 - Swiper Js vertical loop doesn't work properly for react 为什么我的 socket.io 事件侦听器在一个 UI 组件上正常工作,但在 React 中的另一个组件上不起作用? - Why is my socket.io event listener works properly on a UI component but doesn't work on the other in React? 我的 Swiper 应用程序不在 React 中应用淡入淡出效果 - My Swiper app doesn't apply fade effect in React IntelliSense无法与我自己的React组件库一起使用 - IntelliSense doesn't work with my own React component library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM