Home > Article > Web Front-end > How to import pictures in react
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 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!