你能在 Svelte 中通过 props 传递数组吗?

Can you pass an array thru props in Svelte?

你能在 Svelte 中通过 props 传递数组吗?

<script>
    import List
    let array = [];
    console.log(array);
</script>

<List list=array/>
<script>
    export let array;
    console.log(array);
</script>

这将产生: (第一个日志)[] (第二个日志)数组

但我认为它会产生 (第一个日志)[] (第二个日志)[]

是的,您可以将任何值作为 prop 传递。

这里的问题是您正在执行 list=array,它只是传递字符串 "array",而不是 list={array}See the tutorial to learn the syntax.