Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过道具传递包含链接的一串文本?_Javascript_Reactjs - Fatal编程技术网

Javascript 如何通过道具传递包含链接的一串文本?

Javascript 如何通过道具传递包含链接的一串文本?,javascript,reactjs,Javascript,Reactjs,我有几句话要传下来作为一个组件的道具,我想“这里”一词包括一个链接,以便用户可以点击 我尝试用加号来表示字符串,我尝试使用replace(下面的示例) 但我找不到任何解决办法 “replace”方法将[object]保留在此处 示例代码: const textWithoutLink= "First part of the project is on another page. For a full description you can go here for a full expl

我有几句话要传下来作为一个组件的道具,我想“这里”一词包括一个链接,以便用户可以点击

我尝试用加号来表示字符串,我尝试使用replace(下面的示例) 但我找不到任何解决办法

“replace”方法将[object]保留在此处

示例代码:

const textWithoutLink= "First part of the project is on another page. For a 
full description you can go here for a full explanation and walkthrough of 
the project."

const textWithLink= textWithLink.replace('here', <a href= 
'www.page.com'>HERE</a>)

return(
    <projectcard 
         text={textWithLink}
    />
)
const textWithoutLink=“项目的第一部分在另一页上。对于
完整描述您可以在此处对以下内容进行完整解释和演练:
该项目。”
const textWithLink=textWithLink.replace('here',)
返回(
)
将其作为字符串而不是字符串发送:

const fragment = <>
    First part of the project is on another page. For a full description you can go <a href="http://www.page.com">here</a> for a full explanation and walkthrough of the project.
</>;

<ProjectCard 
     text={fragment}
/>
const片段=
项目的第一部分在另一页上。要获得完整的描述,您可以对项目进行完整的解释和演练。
;

如果由于某种原因不可能(但实际上不应该),您可以在
ProjectCard
中使用包含HTML的字符串。但它有这个名字,而且使用起来很尴尬,这是有原因的。:-)


请注意,在上面的示例中,我假设您的组件是
ProjectCard
,而不是
ProjectCard
,因为后者的小写表示React/JSX将假定它是一个HTML元素,而不是React组件。

将其作为字符串发送:

const fragment = <>
    First part of the project is on another page. For a full description you can go <a href="http://www.page.com">here</a> for a full explanation and walkthrough of the project.
</>;

<ProjectCard 
     text={fragment}
/>
const片段=
项目的第一部分在另一页上。要获得完整的描述,您可以对项目进行完整的解释和演练。
;

如果由于某种原因不可能(但实际上不应该),您可以在
ProjectCard
中使用包含HTML的字符串。但它有这个名字,而且使用起来很尴尬,这是有原因的。:-)



请注意,在上面我假设您的组件是
ProjectCard
,而不是
ProjectCard
,因为后者的小写表示React/JSX会假设它是一个HTML元素,而不是React组件。

感谢您的及时回复。这是一个有趣的方法,拓宽了我对道具的视野。谢谢你的及时回复。这是一个有趣的方法,拓宽了我对道具的视野。