svelte-runes
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSvelte Runes
Svelte Runes
Quick Start
快速开始
Which rune? Props: | Bindable: |
Computed: | Side effect: | State:
$props()$bindable()$derived()$effect()$state()Key rules: Runes are top-level only. $derived can be overridden
(use for read-only). Don't mix Svelte 4/5 syntax.
Objects/arrays are deeply reactive by default.
const选择哪个rune? 组件属性: | 可绑定属性: |
计算属性: | 副作用: | 状态:
$props()$bindable()$derived()$effect()$state()核心规则: Runes只能在顶层使用。$derived可以被重写
(使用声明以实现只读)。不要混合使用Svelte 4/5语法。
对象/数组默认是深度响应式的。
constExample
示例
svelte
<script>
let count = $state(0); // Mutable state
const doubled = $derived(count * 2); // Computed (const = read-only)
$effect(() => {
console.log(`Count is ${count}`); // Side effect
});
</script>
<button onclick={() => count++}>
{count} (doubled: {doubled})
</button>svelte
<script>
let count = $state(0); // Mutable state
const doubled = $derived(count * 2); // Computed (const = read-only)
$effect(() => {
console.log(`Count is ${count}`); // Side effect
});
</script>
<button onclick={() => count++}>
{count} (doubled: {doubled})
</button>Reference Files
参考文档
- reactivity-patterns.md - When to use each rune
- migration-gotchas.md - Svelte 4→5 translation
- component-api.md - $props, $bindable patterns
- snippets-vs-slots.md - New snippet syntax
- common-mistakes.md - Anti-patterns with fixes
Forand other template directives, see the svelte-template-directives skill.@attach
- reactivity-patterns.md - 何时使用各个rune
- migration-gotchas.md - Svelte 4→5 迁移指南
- component-api.md - $props、$bindable 使用模式
- snippets-vs-slots.md - 新代码片段语法
- common-mistakes.md - 反模式及修复方案
关于及其他模板指令,请查看 svelte-template-directives 技能文档。@attach
Notes
注意事项
- Use not
onclick,on:clickin layouts{@render children()} - can be reassigned (5.25+) - use
$derivedfor read-onlyconst - Last verified: 2025-01-11
- 使用而非
onclick,在布局中使用on:click{@render children()} - $derived可以被重新赋值(5.25+版本)- 使用声明以实现只读
const - 最后验证时间: 2025-01-11