Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在React中将获取的数据转换为HTML_Reactjs_Wysiwyg - Fatal编程技术网

Reactjs 在React中将获取的数据转换为HTML

Reactjs 在React中将获取的数据转换为HTML,reactjs,wysiwyg,Reactjs,Wysiwyg,我正在获取数据,我获取的其中一个数据如下所示 <p><strong>This is my first content and it is supposed to represent my index.</strong></p> 这是我的第一个内容,它应该代表我的索引。 这是服务器上的wysiwyg输出,当我试图将其带到屏幕上时,我得到了它的原样 请告诉我如何将这些数据以html格式导入我的页面。危险的html 下面是一个例子 function

我正在获取数据,我获取的其中一个数据如下所示

<p><strong>This is my first content and it is supposed to represent my index.</strong></p>
这是我的第一个内容,它应该代表我的索引。

这是服务器上的wysiwyg输出,当我试图将其带到屏幕上时,我得到了它的原样

请告诉我如何将这些数据以html格式导入我的页面。

危险的html 下面是一个例子

function createMarkup() {
  return {__html: 'First &middot; Second'};
}

function MyComponent() {
  return <div dangerouslySetInnerHTML={createMarkup()} />;
}
函数createMarkup(){
返回{uuuhtml:'First·;Second'};
}
函数MyComponent(){
返回;
}
就像这个名字暗示的那样,如果你没有对html进行适当的检查,这是危险的

有关这方面的详细信息,请阅读文档 下面是一个例子

function createMarkup() {
  return {__html: 'First &middot; Second'};
}

function MyComponent() {
  return <div dangerouslySetInnerHTML={createMarkup()} />;
}
函数createMarkup(){
返回{uuuhtml:'First·;Second'};
}
函数MyComponent(){
返回;
}
就像这个名字暗示的那样,如果你没有对html进行适当的检查,这是危险的


有关这方面的详细信息,请阅读文档

您可以通过创建对该元素的引用来编译HTML数据,只需将
innerHTML
属性设置为您获取的数据,该数据的值中包含HTML

此片段为您提供了更多信息:

 constructor() {
    super();
    // create reference
    this.titleDiv = React.createRef();

    // this can be whatever you get HTML data from
    this.state ={
      testHTML: "<h1>Test HTML Text</h1>"
    }
  }

  componentDidMount() {
    const element = this.titleDiv.current;
    element.innerHTML = this.state.testHTML;
  }

  render() {
    return (
      // define reference for where you want to set HTML
      <div ref={this.titleDiv}></div>
    )
  }
constructor(){
超级();
//创建引用
this.titleDiv=React.createRef();
//这可以是从中获取HTML数据的任何内容
这个州={
testHTML:“测试HTML文本”
}
}
componentDidMount(){
常量元素=this.titleDiv.current;
element.innerHTML=this.state.testHTML;
}
render(){
返回(
//为要设置HTML的位置定义引用
)
}
您可以在react.js中深入了解
ref

通过创建对该元素的引用,您可以在HTML中编译数据,只需将
innerHTML
属性设置为获取的数据,该数据的值中包含HTML

此片段为您提供了更多信息:

 constructor() {
    super();
    // create reference
    this.titleDiv = React.createRef();

    // this can be whatever you get HTML data from
    this.state ={
      testHTML: "<h1>Test HTML Text</h1>"
    }
  }

  componentDidMount() {
    const element = this.titleDiv.current;
    element.innerHTML = this.state.testHTML;
  }

  render() {
    return (
      // define reference for where you want to set HTML
      <div ref={this.titleDiv}></div>
    )
  }
constructor(){
超级();
//创建引用
this.titleDiv=React.createRef();
//这可以是从中获取HTML数据的任何内容
这个州={
testHTML:“测试HTML文本”
}
}
componentDidMount(){
常量元素=this.titleDiv.current;
element.innerHTML=this.state.testHTML;
}
render(){
返回(
//为要设置HTML的位置定义引用
)
}
您可以在react.js中深入了解
ref

也许这会回答你的问题:也许这会回答你的问题: