【React】在REACT里怎么引用图片了?

【React】在REACT里怎么引用图片了?

这个要怎么引用啊?

回答

本地<img src={require('xxx.jpg')} />
外链<img src={'imgurl'} />

<img src={require('path/xx.jpg')} />

目录的相对路径

没什么区别, 绝对路径记得加http, 一般用相对路径

import '../css/style.styl';

import React from 'react';

import ReactDOM from 'react-dom';

import ReactCSSTransitionGroup from 'react-addons-css-transition-group';

import welHead from '../images/wel-bg-head.png';

import wel1 from '../images/wel-t1.png';

import wel2 from '../images/wel-t2.png';

import wel3 from '../images/wel-t3.png';

import wel4 from '../images/wel-t4.png';

import ruleBtn from '../images/wel-rule-btn.png';

import goBtn from '../images/wel-go-btn.png';

import r1 from '../images/rule-t1.png';

import r2 from '../images/rule-t2.png';

import r3 from '../images/rule-t3.png';

import r4 from '../images/rule-t4.png';

import r5 from '../images/rule-t5.png';

import r6 from '../images/rule-t6.png';

import backBtn from '../images/rule-back-btn.png';

import messageBg from '../images/message-bg.png';

import opt1 from '../images/opt-1.png';

import opt2 from '../images/opt-2.png';

import opt3 from '../images/opt-3.png';

import opt4 from '../images/opt-4.png';

import opt5 from '../images/opt-5.png';

import submitBtn from '../images/submit-btn.png';

//现在用这方式我都醉了。。。。求正解?

跟普通img标签一样,没有区别

import imgSrc from "../images/user2.jpg

<img src={imgSrc} />

使用url-loader + img-loader

以上是 【React】在REACT里怎么引用图片了? 的全部内容, 来源链接: utcz.com/a/75114.html

回到顶部