Html 在CodeMirror编辑器中输入的内容未在预览div中正确呈现
我的页面上有一个codemirror组件,看起来像:Html 在CodeMirror编辑器中输入的内容未在预览div中正确呈现,html,reactjs,codemirror,Html,Reactjs,Codemirror,我的页面上有一个codemirror组件,看起来像: <CodeMirror value={this.state.value} options={options} onBeforeChange={(editor, data, value) => { this.setState({value: value}); }} onChange={(editor
<CodeMirror
value={this.state.value}
options={options}
onBeforeChange={(editor, data, value) => {
this.setState({value: value});
}}
onChange={(editor, data, value) => {
}}
/>
预览只是从redux获取值:
<div className="preview">
<h2>Preview</h2>
{editor.preview}
</div>
预览
{editor.preview}
我看到的是,如果我在编辑器中输入HTML,它会在浏览器中显示HTML标记,而不是像h1或粗体字符一样显示渲染元素
为什么HTML呈现不正确,而是显示实际的HTML标记?您不能用您尝试的方式设置HTML:
{htmlText}
因为XSS,您可以用尝试的方式尝试它。您不能用尝试的方式设置HTML:{htmlText}
因为XSS,您可以用
<div className="preview">
<h2>Preview</h2>
{editor.preview}
</div>