Skip to main content
基本 Svelte
介绍
反应性
属性
逻辑
事件
绑定
类和样式
动作
转换
高级 Svelte
高级反应性
重用内容
运动
高级绑定
高级转换
上下文 API
特殊元素
<script module>
后续步骤
基本 SvelteKit
介绍
路由
加载数据
标题和 cookie
共享模块
表单
API 路由
$app/state
错误和重定向
高级 SvelteKit
钩子
页面选项
链接选项
高级路由
高级加载
环境变量
结论

到目前为止,我们只处理了内部状态 - 也就是说,这些值只能在给定的组件内访问。

¥So far, we’ve dealt exclusively with internal state — that is to say, the values are only accessible within a given component.

在任何实际应用中,你都需要将数据从一个组件传递到其子组件。为此,我们需要声明属性,通常缩写为 ‘props’。在 Svelte 中,我们使用 $props 符文来实现这一点。编辑 Nested.svelte 组件:

¥In any real application, you’ll need to pass data from one component down to its children. To do that, we need to declare properties, generally shortened to ‘props’. In Svelte, we do that with the $props rune. Edit the Nested.svelte component:

Nested
<script>
	let { answer } = $props();
</script>
<script lang="ts">
	let { answer } = $props();
</script>
上一页 下一页
1
2
3
4
5
6
<script>
	import Nested from './Nested.svelte';
</script>
 
<Nested answer={42} />