我想要实现的是将组件传递到变量的字符串或一些类似的解决方案中。我尝试过 {@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有一定的答案,但我未能使其发挥作用。
我正在尝试在 Svelte Kit 中创建一个自定义元素,就像<svelte:options tag="my-element" /> 文档中的一行所说,您必须添加此行,customElemet:true但是在哪里?Svelte Kit 没有带rollup.config.js插件,但svelte.config.js没有插件。
你知道在 Svelte Kit 中的哪里添加它吗?