Svelte Runes

$state(...)

2025-06-09

在 [[Svelte]] 中通过 $state 创建响应式状态,当状态发生变化时,对应 UI 也会同步响应。

使用

点击按钮时,会同步更新:

<script>
let count = $state(0);
</script>
<button onclick={() => count++}>
clicks: {count}
</button>