Svelte 中的计算属性:反应性声明

1 前言

不知道为什么翻译成“反应性”,而不是“响应式”,因为不是选项式 API,计算属性在 Svelte 中的写法会是怎样的呢?

2 正文

Svelte 中的计算属性使用 $: 起手作变量声明,它会在等号右边依赖的值变化时自动计算。

<script>
  let count = 3;
  $: dbCount = count * 2; // here
  const increment = () => count++;
</script>

<button on:click={increment}>{count} - {dbCount}</button>

3 总结

新符号 get: $: xx = bb * aa

4 参考

原文地址:https://www.cnblogs.com/aisowe/p/15245483.html