You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Svelte具名插槽始终显示回退内容,问题出在哪?

问题原因与解决方法

你的问题出在命名插槽的属性使用错误:Svelte中给插槽内容指定对应插槽名称时,应该用slot属性,而非你写的name属性。

修正后的代码

App.svelte

<script>
    import PageWrapper from './PageWrapper.svelte'
</script>

<PageWrapper>
  <div slot="cover">
    My cover
  </div>
</PageWrapper>

PageWrapper.svelte(无需修改)

The cover is:
<slot name="cover">no cover</slot>

修改后运行,结果就会显示:

The cover is: My cover

内容的提问来源于stack exchange,提问作者marielle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 14:30:59