简体   繁体   中英

How can I import local(my system) png file into React app?

首先,我尝试从执行此操作的api中获取.png图标,但由于使用了标签,浏览器将其呈现为图像,或者即使我想从本地系统导入,也仍会使用呈现为图像文件标签...

you can use the below-mentioned solution. As its created a separate component for Icon like

import React, { PropTypes } from "react";

const Icon = props => {
    const styles = {
        img: {
            width: `${props.size}`,
            height: `${props.size}`
        }
    };
    return <img style={styles.img} src={props.icon} />;
};

Icon.propTypes = {
    size: PropTypes.string,
    icon: PropTypes.string.isRequired
};

Icon.defaultProps = {
    size: 32
};

export default Icon;

More details Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM