Home > Web Front-end > JS Tutorial > body text

How to import pictures in react

coldplay.xixi
Release: 2020-11-17 15:49:49
Original
2135 people have browsed it

How to introduce images in react: 1. Method one [import tsIcon from '../images/typescript.jpeg';]; 2. Method two [const tsIcon = require( './images/typescript';] 】.

How to import pictures in react

How to introduce images in react:

Method 1:

import tsIcon from '../images/typescript.jpeg';
Copy after login

Method Two:

const tsIcon = require( '../images/typescript.jpeg');
Copy after login

Usage method one:

<img src={tsIcon} alt= "" />
Copy after login

Usage method two:

<div style={{ background: `url(${tsIcon}) no-repeat`}}> </div>
Copy after login

Usage method three:

const styles = { test: { background: `url(${tsIcon}) no-repeat center` }}render() { return ( <div style={styles.test}></div> )}
Copy after login

Related free learning recommendations: JavaScript(Video)

The above is the detailed content of How to import pictures 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!