javascript - SemanticUI/ReactJS 模态不支持 html 内容
问题描述
我使用ReactJS
and SemanticUI
,想使用modal
但看起来html
里面不支持它,对吗?只显示纯文本。好吧,我制作了一个显示模态的组件,称为Alert
:
<Modal
open={this.props.open}
size={this.props.size}
content={this.props.content}
actions={[
{ key: 'no', content: this.props.actions, positive: false, onClick: this.props.close }
]}
/>
在一个页面中,我在点击时显示警报:
goBuy = (e) => {
let obj = {
size: 'tiny',
actions: 'nope',
click: this.goSpend,
content: 'Are you sure?',
}
this.setState({
alert: obj,
alertOpen: true,
})
}
它工作正常,但现在我想在内容中添加一些 html 代码,如下所示:
content: 'Are you <b>sure</b>?',
但这不起作用并像纯文本一样显示html代码,而不是使其粗体。知道如何解决这个问题吗?
Are you <b>sure</b>?
但是想要这个:
你确定吗?
解决方案
这里的问题是模态本身认为您传递给content
的值是一个文本值,因此模态显示与您提供的完全相同的单词。<br>
因此,您可以将 jsx 作为内容传递并像这样渲染它,而不是在那里传递您的标签。
const content = {
return(<p>Are you <b>sure</b></p>);
}
goBuy = (e) => {
let obj = {
size: 'tiny',
actions: 'nope',
click: this.goSpend,
content: {content },
}
this.setState({
alert: obj,
alertOpen: true,
})
}
推荐阅读
- testing - 确保即使在“@Timeout”之后也执行清理代码
- javascript - 文件属性在请求负载中显示为空对象
- javascript - 如何针对鼠标悬停事件中的元素 id 值进行测试?
- java - Java:使绘图程序全屏运行
- visual-studio - 如何为 x86 构建和安装 OpenCV 4.2.0?
- python - 在 Python 中将边导入 networkx 库
- tensorflow - 使用 Keras 进行秃头检测
- java - 在 PHP 中使用 ZipArchive 进行损坏的提取
- python - 将Dataframe中的列转换为日期时间
- python - 自定义 rnn 迁移到 tensorflow 2.0