Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

css - Why is my image not loading even though the code is correct?

there is no compile errors and my pages load. However, my images don't display when they're called using CSS. Example below. From doing research, I saw something about a web pack but I tried to install file loader NPM and it didn't work. Thank you!

No compile errors

<Img src={img} alt={alt} />

img: require("../../imgs/platform.jpg").default

another example where it don't work.

export const ContentOne = {
  BGLight: false,
  lightTopLine: true,
  TextPoint: true,
  TitleMain: "SECURE APP",
  description:
    "Group 35’s project works towards solving the zero hunger owards solving the zero hunger SGGS because, our group will design and develop a full stack web-based application that enables kdkdd djkjdkdjf ekjejkkj skfjjskf SGGS because, our group will design and develop a full stack web-based application that enables owards solving the zero hunger SGGS because, our group will design and owards solving the zero hunger SGGS because, our group will design and develop a full stack web-based application that enables  develop a full stack web-based application that enables restaurants, supermarkets and food banks to effectively communicate to not waste food. Therefore, with this effective communication tool, homeless people will have an increased chance in not going hungry and missing meals.  ",
  img: require("../../imgs/genericbackground.jpg").default,
  alt: "img",
  TextPointDesc: true,
};
question from:https://stackoverflow.com/questions/65947694/why-is-my-image-not-loading-even-though-the-code-is-correct

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try just importing it instead?

Heres an example you might be able to use for your content array:

https://codesandbox.io/s/compassionate-ellis-qitz4?file=/src/App.js

import img from "./img/img.jpg"
//const img = require("./img/img.jpg")
const App = () => {
  return  (
    <Img src={img} alt={alt} />
  )

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...