React/Javascript-以字符串形式输出HTML标记
抱歉,如果这是一个简单的问题,我对vanilla JS还相当陌生,并会做出反应 是否可以在React/JS字符串中输出简单的HTML标记(即;React/Javascript-以字符串形式输出HTML标记,javascript,reactjs,jsx,Javascript,Reactjs,Jsx,抱歉,如果这是一个简单的问题,我对vanilla JS还相当陌生,并会做出反应 是否可以在React/JS字符串中输出简单的HTML标记(即;) 这就是我目前正在处理的问题 renderArtistFeatures() { const createFeatures = [ { feature: 'free', Icon: FreeIcon, title: 'Main title',
)
这就是我目前正在处理的问题
renderArtistFeatures() {
const createFeatures = [
{
feature: 'free',
Icon: FreeIcon,
title: 'Main title',
copy: 'Some sample text with a <strong>HTML tag</strong>'
}
].map(({ feature, Icon, title, copy }, i) => {
const klass = `create-feature create-feature--${feature} column small-24 medium-8`;
return (
<div key={i} className={klass}>
<div className="create-feature__inner">
<div className="create-feature__icon create-feature__icon--free">
<Icon />
</div>
<div className="create-feature__content">
<h2 className="create-feature__title">{title}</h2>
<p>{copy}</p>
</div>
</div>
</div>
);
});
return (
// My other code is output here
);
}
renderatistfeatures(){
常量createFeatures=[
{
特色:"免费",,
图标:FreeIcon,
标题:'主标题',
复制:'一些带有HTML标记的示例文本'
}
].map({特征、图标、标题、副本},i)=>{
const klass=`create feature create feature--${feature}列small-24 medium-8`;
返回(
{title}
{copy}
);
});
返回(
//我的另一个代码在这里输出
);
}
正如您所看到的,我试图使用HTML标记输出一些粗体文本,但显然它不起作用
任何帮助都将不胜感激。JSX在使用babel.js在浏览器中运行之前编译为javascript。 如果生成的代码来自:显然“复制只是一个字符串”
“严格使用”;
函数renderatistfeatures(){
var createFeatures=[{
特色:"免费",,
图标:FreeIcon,
标题:'主标题',
复制:'一些带有HTML标记的示例文本'
}].map(函数(_ref,i){
变量特征=_ref.feature,
图标=_ref.Icon,
title=_ref.title,
复制=_ref.copy;
var klass='create feature create feature--'+feature+'column small-24 medium-8';
返回React.createElement(
"div",,
{key:i,className:klass},
React.createElement(
"div",,
{className:'create-feature\uuuu-inner'},
React.createElement(
"div",,
{className:'create-feature\uuuuu icon create-feature\uuuu icon--free'},
React.createElement(图标,null)
),
React.createElement(
"div",,
{className:'create-feature\uuuu content'},
React.createElement(
“h2”,
{className:'create-feature\uuuu title'},
标题
),
React.createElement(
"p",,
无效的
复制
)
)
)
);
});
}
RenderatistFeatures();
您可以在返回之前使用类似的方法:
const copyText = document.createElement("span");
copy.innerHTML = copy;
然后在返回中使用此copyText
const copyText = document.createElement("span");
copy.innerHTML = copy;