解析后端返回的帶有標(biāo)簽的數(shù)據(jù)內(nèi)容
使用 dangerouslySetInnerHTML 方法(react)
const html = {__html:record.content};
console.log(html); // {__html: "<p>這里是返回的帶標(biāo)簽的內(nèi)容</p>"}
return <span dangerouslySetInnerHTML={html}></span>
這個(gè)方法會(huì)導(dǎo)致XSS(跨站腳本)攻擊
去掉后端返回的帶有標(biāo)簽的數(shù)據(jù)
使用正則就可以
eg:
record.content="<p>11111</p>"
const content = record.content.replace(/<.*?>/ig,"")
console.log(content ); // 1111
```