【发布时间】:2018-04-05 14:20:58
【问题描述】:
我正在使用 ReactJS,我需要在 JSX 中添加可见的 HTML 注释(在 html 源代码中),但我不知道该怎么做。
第三方供应商需要此注释来对 cmets 之间的 html 进行一些处理。
<!-- trans_disable_start -->
<div> testing </div>
<!-- trans_disable_end-->
我尝试了以下选项,但评论在 html 源代码中不可见。
{/* <!-- trans_disable_start -->*/}
尝试使用这个库 - react-render-html
{renderHTML('<!-- trans_disable_start -->')}
感谢任何想法/想法。
更新 1:
我尝试使用下面的 JS 库,但这不起作用,因为我使用的是服务器端渲染,并且我在初始加载时在页面源中看到以下值(而不是评论)
https://github.com/optimalisatie/react-jsx-html-comments
<react-comment data-reactid="18">trans_disable_start</react-comment>
【问题讨论】:
-
尝试不使用花括号。例如。例如
/* test */ -
尝试不使用花括号,但出现解析错误。错误:意外的令牌
-
在我发送答案后找到它。也许有帮助。
-
另外this 也可能有帮助