小编Tom*_*dku的帖子

有什么方法可以将组件/html 传递到 Svelte 中的字符串中吗?

我想要实现的是将组件传递到变量的字符串或一些类似的解决方案中。我尝试过 {@html someVariable} 但它只对我有用,它意味着从字符串到 HTML 的文本。但我需要从 HTML 到字符串的文本。我尝试过 document.elementById() 但总是返回“文档未定义”。这是我想要实现的目标的示例:

App.svelte

<script>
import Component from './component.svelte';
import Description  from './description .svelte';


// How to declare component/html into variable?

let test = 'something like <Component /> but acceptable by variable'
let lala = test;

</script>

<Description {test} />  
Run Code Online (Sandbox Code Playgroud)
Description.svelte

<script>
export let lala;
</script>

{#if something}
{@lala html}
{:else if something }
nope
{/if}
Run Code Online (Sandbox Code Playgroud)

我认为这个问题Rendering Svelte Components from HTML string有一定的答案,但我未能使其发挥作用。

javascript string components svelte

3
推荐指数
1
解决办法
3020
查看次数

我应该在 Svelte Kit 中的哪里添加“customElemet:true”?

我正在尝试在 Svelte Kit 中创建一个自定义元素,就像<svelte:options tag="my-element" /> 文档中的一行所说,您必须添加此行,customElemet:true但是在哪里?Svelte Kit 没有带rollup.config.js插件,但svelte.config.js没有插件。

你知道在 Svelte Kit 中的哪里添加它吗?

element svelte sveltekit

3
推荐指数
1
解决办法
1081
查看次数

标签 统计

svelte ×2

components ×1

element ×1

javascript ×1

string ×1

sveltekit ×1