如何在 React 中渲染字符串和 html 标签。我只想在 10 秒内将重定向添加到下一行,但我得到的是 [object object]。
tip={"Please wait!" +<br/ >+"Redirecing in 10 seconds..."}
演示: CodeSandbox Link
最佳答案
根据the Doc :
Tip
应为 string
,使用 \n
进行换行并添加 whiteSpace: "break-spaces
到 Spin
的样式:
<Spin tip={"Please wait! \n Redirecing in 10 seconds..."} style={{ whiteSpace: "break-spaces"}}>
ReactDOM.render(
<antd.Spin tip={"Please wait! \n Redirecing in 10 seconds..."} style={{ whiteSpace: "break-spaces"}}>
<antd.Alert
message="Alert message title"
description="Further details about the context of this alert."
type="info"
/>
</antd.Spin>,
document.getElementById("container")
);
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/antd/4.0.2/antd.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/antd/4.0.2/antd.min.js"></script>
<div id="container"></div>
关于javascript - react |在jsx中渲染html标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60637643/