设置背景图像反应

时间:2017-05-21 17:38:04

标签: javascript reactjs

<div style={{backgroundImage: 'url(this.state.image)'}}>Hello World!</div>

这是我的代码。它不起作用。我试图根据发送到组件的道具来设置背景。

1 个答案:

答案 0 :(得分:3)

尝试使用模板字符串而不是普通字符串:

style = {{backgroundImage: `url(${this.state.image})`}}

style = {{backgroundImage: 'url(' + this.state.image + ')'}}
相关问题