想要在我的模板中直接显示 html 标记。
这是我正在编写要显示的 html 代码的文件。我想显示所有的 html 元素。
import React from 'react';
const html = (
<div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
);
export default html
组件文件
import React, { Component } from 'react';
import html from './code/htmlCodeSnippet';
...
render() {
return (
<div>
{html}
</div>
)
}
}
我正在导入要在我的组件中显示的 html 文件。我将使用 html 荧光笔来显示代码。
每当我参考{html}
,它不显示所有 html 元素。它只是显示为
1
2
3
你需要做一些改变。第一次改变html
到一个字符串,即
const html = `
<div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
<p>hello</p>
</div>`;
And use pre
and code
要换行的元素html
在渲染方法中,即
<pre><code>{html}</code></pre>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)