相当于 React 的 props.children?

Svelte equivalent of React's props.children?

我在 svelte 3 的任何地方都没有发现这个功能.. 我希望它是这样的..

App.svelte

<Error>
   <p>Can't connect to the server!</p>
</Error>`

Error.svelte

<div>{props.children}</div>

我想要App.svelte显示:

<div><p>Can't connect to the server!</p></div>

我只知道如何使用 React props.children。

您可以使用 slot。它是 svelte 提供的一个组件。您可以在您的组件中使用它。传递给组件的任何内容都将代替 slot

呈现

在您的 error.svelte

中试试这个
<div>
    <slot />
</div>