我正在使用来自https://www.material-tailwind.com/docs/react/carousel的react carousel
轮播使用库存图片进行渲染,但当我使用本Map片,甚至是来自其他在线来源的图片时,轮播不进行渲染。为什么会这样?我如何使它适用于本Map片?
我试着改变:
src="https://images.unsplash.com/photo-1493246507139-91e8fad9978e?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80"
字符串
地址:src="./images/image 1”
&
src="../images/image1”
我甚至尝试导入图像使用这两个路径的情况下,我是不正确的,它不会渲染。
完整代码如下:
import { Carousel, Typography, Button } from "@material-tailwind/react";
export function CarouselWithContent() {
return (
<Carousel className="rounded-xl">
<div className="relative h-full w-full">
<img
src="https://images.unsplash.com/photo-1497436072909-60f360e1d4b1?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2560&q=80"
alt="image 1"
className="h-full w-full object-cover"
/>
<div className="absolute inset-0 grid h-full w-full place-items-center bg-black/75">
<div className="w-3/4 text-center md:w-2/4">
<Typography
variant="h1"
color="white"
className="mb-4 text-3xl md:text-4xl lg:text-5xl"
>
The Beauty of Nature
</Typography>
<Typography
variant="lead"
color="white"
className="mb-12 opacity-80"
>
It is not so much for its beauty that the forest makes a claim
upon men's hearts, as for that subtle something, that quality
of air that emanation from old trees, that so wonderfully changes
and renews a weary spirit.
</Typography>
<div className="flex justify-center gap-2">
<Button size="lg" color="white">
Explore
</Button>
<Button size="lg" color="white" variant="text">
Gallery
</Button>
</div>
</div>
</div>
</div>
<div className="relative h-full w-full">
<img
src="https://images.unsplash.com/photo-1493246507139-91e8fad9978e?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80"
alt="image 2"
className="h-full w-full object-cover"
/>
<div className="absolute inset-0 grid h-full w-full items-center bg-black/75">
<div className="w-3/4 pl-12 md:w-2/4 md:pl-20 lg:pl-32">
<Typography
variant="h1"
color="white"
className="mb-4 text-3xl md:text-4xl lg:text-5xl"
>
The Beauty of Nature
</Typography>
<Typography
variant="lead"
color="white"
className="mb-12 opacity-80"
>
It is not so much for its beauty that the forest makes a claim
upon men's hearts, as for that subtle something, that quality
of air that emanation from old trees, that so wonderfully changes
and renews a weary spirit.
</Typography>
<div className="flex gap-2">
<Button size="lg" color="white">
Explore
</Button>
<Button size="lg" color="white" variant="text">
Gallery
</Button>
</div>
</div>
</div>
</div>
<div className="relative h-full w-full">
<img
src="https://images.unsplash.com/photo-1518623489648-a173ef7824f3?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2762&q=80"
alt="image 3"
className="h-full w-full object-cover"
/>
<div className="absolute inset-0 grid h-full w-full items-end bg-black/75">
<div className="w-3/4 pl-12 pb-12 md:w-2/4 md:pl-20 md:pb-20 lg:pl-32 lg:pb-32">
<Typography
variant="h1"
color="white"
className="mb-4 text-3xl md:text-4xl lg:text-5xl"
>
The Beauty of Nature
</Typography>
<Typography
variant="lead"
color="white"
className="mb-12 opacity-80"
>
It is not so much for its beauty that the forest makes a claim
upon men's hearts, as for that subtle something, that quality
of air that emanation from old trees, that so wonderfully changes
and renews a weary spirit.
</Typography>
<div className="flex gap-2">
<Button size="lg" color="white">
Explore
</Button>
<Button size="lg" color="white" variant="text">
Gallery
</Button>
</div>
</div>
</div>
</div>
</Carousel>
);
}
型
2条答案
按热度按时间z4bn682m1#
您可以将图像存储在
public
文件夹中(当您使用Vite
创建react应用程序时,它会在项目中创建一个名为public folder的文件夹)。然后您可以在<image/>
的src
属性中使用该路径,如下所示。x1c 0d1x的数据
// CarouselWithContent.jsx文件
字符串
wgmfuz8q2#
我想通了.我只是不得不把我的carousel组件的组件文件夹,让这工作.无论出于何种原因,没有路径将从图像文件夹和组件文件夹工作,我必须有一个或另一个.这些事情似乎只发生在我不会再使用的react-app.谢谢