Skip to content
On this page

computedEager

Eager computed without lazy evaluation.

Learn more at Vue: When a computed property can be the wrong tool.

  • Use computed() when you have a complex calculation going on, which can actually profit from caching and lazy evaluation and should only be (re-)calculated if really necessary.
  • Use computedEager() when you have a simple operation, with a rarely changing return value – often a boolean.

例子

Lazy Computed
Is over 5: false
Renders: 0
Eager Computed
Is over 5: false
Renders: 0
Count: 0

Usage

js
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
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

Type Declarations

typescript
export declare function computedEager<T>(
  fn: () => T,
  options?: WatchOptionsBase
): Readonly<Ref<T>>
export { computedEager as eagerComputed }
export declare function computedEager<T>(
  fn: () => T,
  options?: WatchOptionsBase
): Readonly<Ref<T>>
export { computedEager as eagerComputed }

Source

Category
Export Size
468 B
Last Changed
last year
Alias
eagerComputed

SourceDemoDocs

贡献者(Contributors)

日志(Changelog)

No recent changes

Released under the MIT License.