How to reference images in react: 1. Import the image path, the code is [import Img from "./images/1.png"]; 2. Get the image directly, the code is [】.
#The operating environment of this tutorial: windows7 system, React17 version, thinkpad t480 computer.
How to reference images in react:
The first way to import the image path
import Img from "./images/1.png" <img src={Img} alt=""/>
The second way Get the picture directly
<img src={require("./images/1.png")} alt=""/>
If it is a background image, operate style
style={{background:`url(${require("./images/1.png")})` }}
Related learning recommendations: js video tutorial
The above is the detailed content of How to quote images in react. For more information, please follow other related articles on the PHP Chinese website!