在使用antd实现轮播图的时候发现了这样一个问题:
当我使用map对图片的路径遍历时会报错:Cannot find module '../../../images/penuins1.jpg'
但是当我不使用遍历,重复的写几个<Image src={require( '../../../images/penuins1.jpg')} /> 就是好用的 想知道这是为什么呢?
====================================================================
补充:在我将路径设置绝对路径时,会出现图片不显示的问题
const images = [
'src/images/penuins1.jpg',
'src/images/penuins2.jpg',
'src/images/penuins3.jpg',
'src/images/penuins4.jpg',
'src/images/penuins5.jpg',
]
return (
<div className="home_show">
<div className="home_show_scroll">
<Carousel autoplay>
{images.map((image, index) => (
<div key={index}>
<Image className="home_show_contentStyle" src={image} />
</div>
))}
</Carousel>
</div>
</div>
)
====================================================================
export default function HomePageShow() {
const images = [
'../../../images/penuins1.jpg',
'../../../images/penuins2.jpg',
'../../../images/penuins3.jpg',
'../../../images/penuins4.jpg',
'../../../images/penuins5.jpg',
]
return (
<div className="home_show">
<div className="scrollImg">
<Carousel autoplay>
{images.map((image, index) => (
<div key={index}>
<Image src={require(image)} />
</div>
))}
</Carousel>
</div>
</div>
)
}