[英]Inline style background-image does not display local images in Reactjs with a variable
enter image description here strong text在此处输入图像描述强文本
enter image description here在此处输入图像描述
Can someone tell me what I did wrong with the inline style?有人可以告诉我内联样式做错了什么吗? when I set the background-image in css file, it display the picture.
当我在 css 文件中设置背景图像时,它会显示图片。
Try adding height and width on your style object尝试在您的样式 object 上添加高度和宽度
const style = {
backgroundImage: `url(pic_${num}`,
height: "200px",
width: "200px"
}
since div has no content consider adding width and height.由于 div 没有内容,请考虑添加宽度和高度。 If it doesn't work please edit your question or show us what is passed in the
num
variable or maybe show us whats going on the console.如果它不起作用,请编辑您的问题或向我们展示
num
变量中传递的内容,或者向我们展示控制台上发生了什么。
I figured out that the problem is image loading.我发现问题是图像加载。 I sorted it out by moving the images folder to public folder and then all the images loaded smoothly.
我通过将图像文件夹移动到公用文件夹来整理它,然后顺利加载所有图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.