我真的很喜欢“react-responsive-carousel”,它完全符合我的要求。
更多细节: https ://www.npmjs.com/package/react-responsive-carousel
但是我意识到这个提供的演示示例使用静态图像,放置在单独的“Carousel.js”文件中。
就我而言,我想在 Carousel 中加载图像,我在运行时使用 API 获取这些图像。我不知道如何实现这种行为。
目前以下是我的应用程序的设置: 文件:Carousel.js
import React from "react";
import { Carousel } from "react-responsive-carousel";
export default () => (
<Carousel autoPlay infiniteLoop='true'>
<div>
<img src="http://example.com/image/32.png" />
<p className="legend">Image 1</p>
</div>
<div>
<img src="http://example.com/image/34.png" />
<p className="legend">Image 2</p>
</div>
<div>
<img src="http://example.com/mockups/image/9.png" />
<p className="legend">Image 3</p>
</div>
<div>
<img src="http://example.com/image/32.png" />
<p className="legend">Image 4</p>
</div>
<div>
<img src="http://example.com/image/34.png" />
<p className="legend">Image 5</p>
</div>
</Carousel>
);
在我的App.js
文件中,我只是通过以下方式使用它:
<div>
<div className="my-carousel">
<Carousel />
</div>
</div>