在标记中包含链接,该链接<p>从 Svelte 中的 JSON 获取其内容



我是Svelte和Sapper的新手,我正在将其用于我的新项目。实现的一部分涉及制作多个卡,我在本节中用JSON为其声明了数据,然后使用迭代来创建多个卡。

我需要在段落中包含一个链接,但我找不到变通方法。从长远来看,我的代码基本上是这样的——

<script>
let cards = [
{
paragraphText: "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
},
{
paragraphText: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. This is where my link goes <a href="xyz.com">HYPERLINK</a>"
}
]
</script>
{#each cards as card}
<div class="card">
<p>{card.paragraphText}</p> <!-- This is the paragraph that contains a hyperlink anchor tag inside it -->
</div>
{/each}

您应该能够使用@html助手来呈现html内容:

{#each cards as card}
<div class="card">
<p>{@html card.paragraphText}</p> <!-- This is the paragraph that contains a hyperlink anchor tag inside it -->
</div>
{/each}

最新更新