反应内联样式

时间:2016-02-16 22:14:56

标签: reactjs

如何应用内联样式以获得背景图像?以下代码不起作用

Header = React.createClass({
    render(){
    let headerStyle = {
        backgroundImage : url('about.jpg')
    };

    return (<header className="intro-header" style={headerStyle}>
    <div className="container">Some text</div></header>);

    }})

它会返回错误:

Uncaught ReferenceError: url is not defined

2 个答案:

答案 0 :(得分:0)

您需要传递一个字符串值:

backgroundImage: "url('about.jpg')"

就像使用标准DOM CSS API一样。您不希望url('about.jpg')被解释为JS。

答案 1 :(得分:0)

内联样式是这样的;

&#13;
&#13;
    // Initialize Stetho
    Stetho.initialize(
            Stetho.newInitializerBuilder(this)
                    .enableDumpapp(new SampleDumperPluginsProvider(this))
                    .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
                    .build());
&#13;
&#13;
&#13;