React不能直接使用style等属性

错误消息:Uncaught Error: Minified React error #62; visit http://facebook.github.io/react/docs/error-decoder.html?invariant=62&args[]=%20This%20DOM%20node%20was%20rendered%20by%20%60ProductRow%60. for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

错误出处:

const name=this.props.product.stocked ? this.props.product.name :
    <span style='color:"red"'>
        {this.props.product.name}
    </span>;
return(
    <tr>
        <td>{name}</td>
        <td>{this.props.product.price}</td>
    </tr>
)

其中color:red 是错误的原因;

正确的写法如下

    const name=this.props.product.stocked ? this.props.product.name :
        <span style={{color:"red"}}>
            {this.props.product.name}
        </span>;
    return(
        <tr>
            <td>{name}</td>
            <td>{this.props.product.price}</td>
        </tr>
    )

React可能给的连接是:

https://facebook.github.io/react/docs/error-decoder.html?invariant=62&args[]=%20This%20DOM%20node%20was%20rendered%20by%20%60ProductRow%60

或者

https://facebook.github.io/react/docs/error-decoder.html?invariant=31&args[]=object%20with%20keys%20%7B%7D&args[]=

~~

未经允许不得转载:朱邦邦的博客 » React不能直接使用style等属性

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址