编程技术记录

世界你好!

我初学React,懵懵懂懂,我把基础的html语法直接搬到JSX文件中,React提示我:

 Line 17:36:  Style prop value must be an object  react/style-prop-object

我写的是:

class CYXQHome extends React.Component {
    render(){
        return (
             <div id="showDiv1" style="display:none;position:relative;left:69px;width:360px" />
             );
      }
}

出现这种错误的原因是style=xxxx那部分,style必须是一个对象 。修改后

<div id="showDiv1" style={ { display:"none",position:"relative",left:"69px",width:"360px" } } />

如上,有两个花括号, {{ {} }} ,外部的{ {} } 表示这是Javascript句法,里面的{ {} } 是一个对象。

参考 http://www.mamicode.com/info-detail-1682242.html

发表回复

© Beli. All Rights Reserved.