简体   繁体   中英

setting background-image using react styling

i am making a project of my own and i am trying to display 3 components that will render a different image for one of them. The image is not displaying, i think the problem is the server is downloading the image as a html/text type. I am new to react and i am having difficulties displaying images...

style={{backgroundImage: url(${props.img}) } }

img={city.imageURL}

imageURL: '/assets/mount-fugji.png'

And by the way, how do i access the style object?

In React you should use:

styles={{ backgroundImage:`url(${picture})` }}

so you can try to edit code like this:

style={{backgroundImage: `url(${props.img})`} }

you can use like

 <div style={{ backgroundImage: `url(${props.img || city.imageURL})` }} />;

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