【问题标题】:rendering new line (\n) as it is in react / html在 react / html 中渲染新行 (\n)
【发布时间】:2020-06-12 07:52:30
【问题描述】:

我正在尝试将换行符呈现为 \n,但它们会自动转换为新行。

const text = "hi\nhi"
<div>{text}</div>

这被渲染为:

hi
hi

在 react/html 中没有任何格式的情况下,如何实际将文本显示为“hi\nhi”?谢谢

【问题讨论】:

    标签: html reactjs newline


    【解决方案1】:

    使用双反斜杠"hi\\nhi",而不是"hi\nhi"

    【讨论】:

      猜你喜欢
      • 2015-06-02
      • 2022-06-17
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 2021-06-07
      • 1970-01-01
      • 2017-12-05
      相关资源
      最近更新 更多