How to import image (.svg, .png ) in a React Component

后端 未结 7 1234
一整个雨季
一整个雨季 2020-12-04 23:30

I am trying to import an image file in one of my react component. I have the project setup with web pack

Here\'s my code for the component

import Di         


        
相关标签:
7条回答
  • 2020-12-04 23:40

    If the images are inside the src/assets folder you can use require with the correct path in the require statement,

    var Diamond = require('../../assets/linux_logo.jpg');
    
     export class ItemCols extends Component {
        render(){
            return (
                <div>
                    <section className="one-fourth" id="html">
                        <img src={Diamond} />
                    </section>
                </div>
            )
        } 
    }
    
    0 讨论(0)
提交回复
热议问题