computedEager

computedEager

遅延評価なしのイージャーコンピューテッド。

::: info この関数は将来のバージョンで削除されます。 :::

::: tip 注意💡: Vue 3.4+を使用している場合、computedをすぐに使用できます。この関数はもう必要ありません。
Vue 3.4+では、コンピューテッドの新しい値が変わらない場合、computedeffectwatchwatchEffectrenderの依存関係はトリガーされません。
参照: https://github.com/vuejs/core/pull/5912 :::

詳細はVue: When a computed property can be the wrong toolをご覧ください。

  • 複雑な計算が行われ、キャッシュと遅延評価から実際に利益を得ることができ、本当に必要な場合にのみ(再)計算されるべき場合は、computed()を使用します。
  • シンプルな操作で、返り値がほとんど変わらない場合(多くの場合はブール値)、computedEager()を使用します。

使用法

import { computedEager } from '@vueuse/core'

const todos = ref([])
const hasOpenTodos = computedEager(() => !!todos.length)

console.log(hasOpenTodos.value) // false
toTodos.value.push({ title: 'Learn Vue' })
console.log(hasOpenTodos.value) // true