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
179 views
in Technique[技术] by (71.8m points)

reactjs - Image doesn't show up in react JS and CSS

I wrote this code in VSCODE and I'm trying to show an image which is clipped as a circle, the overflow of the image will be hidden by the circle. But image does not show up. Browser doesn't provide any error as well. image path is correct as it doesn't throw any errors. If you need any further info, I'll add them.

CSS

 .Pic {
    clip-path: circle(150px at center);
}

React JS

</section> 
<div classname ="Pic">
      <img  width = "150px" height ="150px" src={require("./Assets/profpicjpg.jpg")} alt="" ></img>
      </div>
</section>

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

1 Reply

0 votes
by (71.8m points)

Put default after the require as below:

<img  className="Pic"  width = "150px" height ="150px" src={require("./Assets/profpicjpg.jpg").default} alt="" ></img>

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

...