Javascript 在react中解析标记
我已经创建了这样的对象Javascript 在react中解析标记,javascript,html,reactjs,parsing,Javascript,Html,Reactjs,Parsing,我已经创建了这样的对象 export const homeObjOne ={ lightBg: false, lightText: true, lightTextDesc: true, topLine:'Explore DrukBox', // - working correctly headLine: 'Unlimited printing <br> with us', description: 'Lets <br> be
export const homeObjOne ={
lightBg: false,
lightText: true,
lightTextDesc: true,
topLine:'Explore DrukBox', // - working correctly
headLine: 'Unlimited printing <br> with us',
description: 'Lets <br> begin!', // - output: Lets <br> begin!(with br)
buttonLabel: 'Get Started',
imgStart: '',
img: './assets/svg-1.svg',
alt: 'DrukBox'
}
function HeroSection({
lightBg,topLine,lightText,lightTextDesc,headLine,description,buttonLabel,img, alt, imgStart
}) {
return (
<div className={lightBg ? 'home__hero-section' : 'home__hero-section darkBg'}>
<div className="container">
<div className="row home__hero-row"
style={{display:'flex',flexDirection: imgStart === 'start' ? 'row-reverse' : 'row'}}
>
export const homeObjOne={
lightBg:错,
是的,
是的,
背线:'探索鼓盒',//-工作正常
标题:“与我们无限制印刷”
,
描述:“让
开始!”,//-输出:让
开始!(带br)
按钮标签:“开始”,
imgStart:“”,
img:“./assets/svg-1.svg”,
alt:“鼓点盒”
}
然后把它带到这样的组件上
export const homeObjOne ={
lightBg: false,
lightText: true,
lightTextDesc: true,
topLine:'Explore DrukBox', // - working correctly
headLine: 'Unlimited printing <br> with us',
description: 'Lets <br> begin!', // - output: Lets <br> begin!(with br)
buttonLabel: 'Get Started',
imgStart: '',
img: './assets/svg-1.svg',
alt: 'DrukBox'
}
function HeroSection({
lightBg,topLine,lightText,lightTextDesc,headLine,description,buttonLabel,img, alt, imgStart
}) {
return (
<div className={lightBg ? 'home__hero-section' : 'home__hero-section darkBg'}>
<div className="container">
<div className="row home__hero-row"
style={{display:'flex',flexDirection: imgStart === 'start' ? 'row-reverse' : 'row'}}
>
功能部分({
lightBg、背线、lightText、lightTextDesc、标题、说明、按钮标签、img、alt、imgStart
}) {
返回(
等等
)
}
但在我的html代码未解析的对象中,我尝试了所有类型“,”`
从“/Data”导入{homeObjOne}
函数Home(){
返回(
)
}
导出默认主页
- 这就是我导入对象的方式
addPagesObjOne
创建为一个
要访问此对象内的属性并假设addPagesObjOne
已被删除,请执行以下操作:
- 使用JSX导入到组件中,或
- 在组件文件中
将成为
更新:
我可以看到您已经提供了一个更新,说明了您如何布局代码,您的代码运行良好。也许您的资产不在正确的位置?您可以向我们展示更多组件的信息吗,特别是您如何导入
addPagesObjOne
以及如何使用它?这不是我创建的通用组件的答案,我不能因此更改它否,所有代码都正常工作,有一个我无法将html代码插入到我的道具中。您可能需要更新您的问题以反映您试图解决的问题,因为不清楚到底是什么问题被破坏了。:-)
<img src={img} alt={alt}/>
<img src={addPagesObjOne.img} alt={addPagesObjOne.alt}/>