[英]GIF from SRC folder in React project not showing
I have a component which should display a gif from the "/src/images"
folder.我有一个组件应该显示
"/src/images"
文件夹中的 gif。 Unfortunately that doesn't happen.不幸的是,这并没有发生。 I only get my "old" value displayed.
我只显示我的“旧”值。 What am I doing wrong?
我究竟做错了什么?
Danke.js site: Danke.js 网站:
import Confetti from "../images/confetti.gif";
<Box sx={{ justifyContent: "center", display: "flex" }}>
<img
src={Confetti}
alt="Danke"
width={"50%"}
style={{ borderRadius: "50%", border: "7px solid black" }}
/>
</Box>
Result:结果:
The image file is a local asset within the app, use require
to access the local asset and pass to the src
attribute.图像文件是应用程序内的本地资产,使用
require
访问本地资产并传递给src
属性。 Note that this is different than using a normal path string to an asset in the built public directory.请注意,这与在构建的公共目录中使用资产的普通路径字符串不同。
<img
src={require("../images/confetti.gif")}
alt="Danke"
width={"50%"}
style={{ borderRadius: "50%", border: "7px solid black" }}
/>
or或者
const Confetti = require("../images/confetti.gif");
<Box sx={{ justifyContent: "center", display: "flex" }}>
<img
src={Confetti}
alt="Danke"
width={"50%"}
style={{ borderRadius: "50%", border: "7px solid black" }}
/>
</Box>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.