【问题标题】:The `style` prop expects a mapping from style properties to values, not a string. Style with multiple property`style` 属性需要从样式属性到值的映射,而不是字符串。具有多个属性的样式
【发布时间】:2021-06-04 09:02:13
【问题描述】:

<div style="background: url('images/slider/slider1.jpg') no-repeat fixed center; height: 100vh;">

我有这件作品,我试着让它变成 &lt;div style={{"background: url('images/slider/slider1.jpg') no-repeat fixed center; height: 100vh"}}&gt; 我试图将其更改为&lt;div style={{background: url('images/slider/slider1.jpg') no-repeat fixed center; height: 100vh}}&gt; 否则我试过了 &lt;div style={{"background: url('images/slider/slider1.jpg') no-repeat fixed center, height: '100'vh"}}&gt; 它也不起作用,我需要一些指导和帮助,谢谢!

【问题讨论】:

  • 你可以试试这个吗?样式={{ 背景:“.....” }} .
  • 谢谢,它就像一个魅力。

标签: reactjs


【解决方案1】:

你必须这样写:

{ 背景:“你的所有属性”,高度:“100vh”}

请查看 React 文档:https://reactjs.org/docs/dom-elements.html#style

【讨论】:

  • 谢谢,它停止显示错误,我以前读过但无法弄清楚,我想我会再读一遍。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-08
  • 2018-11-04
  • 2021-11-27
  • 1970-01-01
  • 2017-07-03
相关资源
最近更新 更多