current position:Home>Use of nested HTML

Use of nested HTML

2022-04-29 04:25:50baoleilei6

        Recently doing React There is a problem in the project , Need to put UEditor The content displayed in the editor page , And because the UEditor The content obtained in the editor will include html label , for example <a><p> And so on. , If displayed directly on the page, it will be displayed as a string .

      stay Vue There was a v-html Property can handle this problem , And in the React in , It needs to be used dangerouslySetInnerHTML attribute , The format is as follows :<div dangerouslySetInnerHTML={_html: " I'm a string <b> I'm bold </b>"}  />, It will put... In the string html The label works properly .(tip: Of course, if you use js Of innerHTML When I didn't say )

Define a transformation method

Pass the content into the method as a parameter , Returns a value with dangerouslySetInnerHTML Attribute div



author : Seven zero three
link :https://www.jianshu.com/p/508139ac82e8
source : Simple books
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .

copyright notice
author[baoleilei6],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/117/202204270552176489.html

Random recommended