Home >Web Front-end >JS Tutorial >How to import pictures in react

How to import pictures in react

coldplay.xixi
coldplay.xixiOriginal
2020-11-17 15:49:492201browse

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';

Method Two:

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

Usage method one:

<img src={tsIcon} alt= "" />

Usage method two:

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

Usage method three:

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

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!

Statement:
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