dangerouslySetInnerHTML属性的功用实际上就是显现纯文本内容
import React from 'react';
class SetHtml extends React.Component {
constructor(){
super();
this.state = {
content:'<h1>题目称号</h1>'
}
}
render() {
return (
<div>
<div>
{this.state.content}
</div>
<div dangerouslySetInnerHTML={{__html: this.state.content}} />
</div>
)
}
}
export default SetHtml;
这里如果是直接this.state.content会把h1标签一同显现出来,一切这个时刻就要用到dangerouslySetInnerHTML了,如许只显现内容不会显现标签