Home > Web Front-end > JS Tutorial > What tags are used for images in react

What tags are used for images in react

青灯夜游
Release: 2020-12-18 11:53:30
Original
2545 people have browsed it

In react, images use the "<img>" tag, but the path to the image cannot be written directly in the srcs attribute of the tag. You can use "" to introduce images.

What tags are used for images in react

The operating environment of this tutorial: windows7 system, react16 version. This method is suitable for all brands of computers.

Recommended related tutorials: React video tutorial

The tags used for images in React are the same as those in HTML, which is the <img> tag, which defines the image in the web.

But es6 does not support writing the path of the image directly in the <img> tag, that is, it cannot be used like this <img src="img.png"/>

So how to introduce images into react? Solution:

Introducing images into react, methods that can be used:

1) Recommended use: require method. It should be noted that with this method, only strings can be written in require. , cannot write variables.

<img src={require(&#39;图片url&#39;)} />
Copy after login

2) Import method:

import imgURL from &#39;图片url&#39;;
<img src={imgURL } />
Copy after login

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of What tags are used for 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