React inline styling

2019-09-05 02:07发布

How to apply inline styling in order to have a background-image ? the following code doesn't work

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

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

    }})

it returns an error :

Uncaught ReferenceError: url is not defined

标签: reactjs
2条回答
Root(大扎)
2楼-- · 2019-09-05 02:24

Inline style are like this;

let headerStyle = {
        backgroundImage : "url('about.jpg')"
    };

查看更多
该账号已被封号
3楼-- · 2019-09-05 02:27

You need to pass a string value:

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

just like you'd do with the standard DOM CSS API. You don't want url('about.jpg') to be interpreted as JS.

查看更多
登录 后发表回答