React内联样式 - 样式prop期望从样式属性到值的映射,而不是字符串 [英] React inline style - style prop expects a mapping from style properties to values, not a string

查看:1206
本文介绍了React内联样式 - 样式prop期望从样式属性到值的映射,而不是字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的React应用程序中设置内联样式。在这种情况下,对于跨度:

I am trying to set inline styles in my React application. In this case, for a span:

<span className="myClass" style={{float : 'left', paddingRight : '5px'}} > </span>

React告诉我:


Uncaught Invariant Violation: style prop需要从
样式属性到值的映射,而不是字符串。例如,使用JSX时
style = {{marginRight:spacing +'em'}}。这个DOM节点
由`SentenceView

Uncaught Invariant Violation: The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX. This DOM node was rendered by `SentenceView

呈现。我不太清楚这意味着什么。

I am not quite sure what it means.

PS:我尝试过不同的版本,所以我做了 paddingRight:5 以及 paddingRight:5 +' px'以及 paddingRight:5px ,但我没有任何成功!

PS: I have tried different versions, so I did paddingRight: 5 as well as paddingRight: 5 + 'px' as well as paddingRight : 5px, but I didn't have any success!

推荐答案

使用风格 s 支柱代替风格

<span className="myClass" style={{float : 'left', paddingRight : '5px'}} > </span>

这篇关于React内联样式 - 样式prop期望从样式属性到值的映射,而不是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆