我正在处理一个 Sapper 项目,我想在加载到插槽之前将一些异步数据加载到布局中。我发现在 _layout.svelte 文件中,我无法将道具传递给插槽。
//_layout.svelte
<slot foo={"hello"}></slot>
//index.svelte
<script>
export let foo;
alert(foo); // returns undefined
</script>
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过这个?我想我可以通过在每个插槽/子页面上加载我需要的所有数据来解决它。我能够设置插槽道具的唯一方法是手动访问它。
$$props.$$scope.ctx.level1.props.foo = "hello"
Run Code Online (Sandbox Code Playgroud)