How React parses the content read from the background as html format code (with styles)

   React does not parse the html format code obtained directly from the background, because it is to prevent XSS attacks. What is an XSS attack, which will appear in the next blog. So to let react parse the html format code obtained from the background, the following code is needed, not much to say:

import React from 'react'
class IndexCom extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.state={
            div:'<div style="width: 750px;height: 200px;background: red;color: #fff;"><b>11111111111111</b></div>',
        }
    }
    render() {
        return (
            <div>
                <div className="index">
                    <div dangerouslySetInnerHTML = {{ __html:this.state.div }}></div>
                </div>
            </div>
        )
    }
}
export default IndexCom

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325296139&siteId=291194637