Home > Web Front-end > JS Tutorial > How to quote images in react

How to quote images in react

coldplay.xixi
Release: 2023-01-04 09:36:58
Original
3591 people have browsed it

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 [】.

How to quote images in react

#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=""/>
Copy after login

The second way Get the picture directly

<img src={require("./images/1.png")} alt=""/>
Copy after login

If it is a background image, operate style

style={{background:`url(${require("./images/1.png")})` }}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template