【发布时间】:2019-09-20 07:54:08
【问题描述】:
我使用 url-loader 通过将图像转换为字节来在我的网页中加载图像。
这是我的正常情况,可以正常工作:
import React from 'react';
import accountImg from '../../../../images/setting/account.png';
const Account =(props) => (
<div>
<img src={accountImg} className="img-responsive" style={{"width":"100%"}} ></img>
</div>
);
export default Account;
但是如果我需要动态导入怎么办:
render() {
return (
<img src={ "/images/headers/"+this.props.newsChannel.removeAllSpaces().toLowerCase()+".png"}></img>
);
所以专门针对这种情况:
src={ "/images/headers/"+this.props.newsChannel.removeAllSpaces().toLowerCase()+".png"
如何动态导入 png?
【问题讨论】:
标签: reactjs webpack ecmascript-6 es6-module-loader urlloader