我有一个组件 <Ren1 text="Line1\nLine2\nLine3" />
...
function Ren1({text}){
return <p>{text}</p>;
}
export default Ren1
如何从 \n
添加换行符从什么时候来自数据库?
需要的输出:
Line1
Line2
Line3
预先感谢您的帮助
最佳答案
您可以在不拆分文本值的情况下执行此操作。
首先,在传递文本属性时将花括号括起来:
<Text text={"One \n Two \n Three"} />
然后使用whiteSpace: "pre-line"
样式
<div style={{ whiteSpace: "pre-line" }}>{props.text}</div>
关于javascript - 换行符 - React Prop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67616946/