Попытка получить изображения для показа на слайдах в Карусели, используя тег и имя класса.У меня есть изображения, сохраненные в той же папке, что и файл Slider.js.Я изменил свойство id по умолчанию в массиве items на source и изменил ключ на item.src, но все равно не радуюсь.Я получаю маленький символ изображения на экране, как будто он знает, что он пытается отобразить изображение, но не фактическое изображение, которое я хочу, если это имеет смысл
import React, { Component } from "react";
import {
Carousel,
CarouselItem,
CarouselControl,
CarouselIndicators,
CarouselCaption
} from "reactstrap";
const items = [
{
src: "slider1.jpeg",
altText: "Slide 1",
caption: "Slide 1"
},
{
src: "slider2.jpeg",
altText: "Slide 2",
caption: "Slide 2"
},
{
src: "slider3.jpeg",
altText: "Slide 3",
caption: "Slide 3"
}
];
class Slider extends Component {
constructor(props) {
super(props);
this.state = { activeIndex: 0 };
this.next = this.next.bind(this);
this.previous = this.previous.bind(this);
this.goToIndex = this.goToIndex.bind(this);
this.onExiting = this.onExiting.bind(this);
this.onExited = this.onExited.bind(this);
}
onExiting() {
this.animating = true;
}
onExited() {
this.animating = false;
}
next() {
if (this.animating) return;
const nextIndex =
this.state.activeIndex === items.length - 1
? 0
: this.state.activeIndex + 1;
this.setState({ activeIndex: nextIndex });
}
previous() {
if (this.animating) return;
const nextIndex =
this.state.activeIndex === 0
? items.length - 1
: this.state.activeIndex - 1;
this.setState({ activeIndex: nextIndex });
}
goToIndex(newIndex) {
if (this.animating) return;
this.setState({ activeIndex: newIndex });
}
render() {
const { activeIndex } = this.state;
const slides = items.map(item => {
return (
<CarouselItem
className="custom-tag"
tag="div"
key={item.src}
onExiting={this.onExiting}
onExited={this.onExited}
>
<img src={item.src} alt={item.altText} />
<CarouselCaption
className="text-danger"
captionText={item.caption}
captionHeader={item.caption}
/>
</CarouselItem>
);
});
return (
<div>
<style>
{`.custom-tag {
max-width: 100%;
height: 500px;
}`}
</style>
<Carousel
activeIndex={activeIndex}
next={this.next}
previous={this.previous}
>
<CarouselIndicators
items={items}
activeIndex={activeIndex}
onClickHandler={this.goToIndex}
/>
{slides}
<CarouselControl
direction="prev"
directionText="Previous"
onClickHandler={this.previous}
/>
<CarouselControl
direction="next"
directionText="Next"
onClickHandler={this.next}
/>
</Carousel>
</div>
);
}
}
export default Slider;