Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/computedEager.md
1---2category: Reactivity3alias: eagerComputed4---56# computedEager78Eager computed without lazy evaluation.910::: info11This function will be removed in future version.12:::1314::: tip15Note💡: If you are using Vue 3.4+, you can use `computed` right away, you no longer need this function.16In Vue 3.4+, if the computed new value does not change, `computed`, `effect`, `watch`, `watchEffect`, `render` dependencies will not be triggered.17See: https://github.com/vuejs/core/pull/591218:::1920Learn more at [Vue: When a computed property can be the wrong tool](https://dev.to/linusborg/vue-when-a-computed-property-can-be-the-wrong-tool-195j).2122- 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.23- Use `computedEager()` when you have a simple operation, with a rarely changing return value – often a boolean.2425## Usage2627```ts28import { computedEager } from '@vueuse/core'2930const todos = ref([])31const hasOpenTodos = computedEager(() => !!todos.length)3233console.log(hasOpenTodos.value) // false34toTodos.value.push({ title: 'Learn Vue' })35console.log(hasOpenTodos.value) // true36```3738## Type Declarations3940```ts41export type ComputedEagerOptions = WatchOptionsBase42export type ComputedEagerReturn<T = any> = Readonly<ShallowRef<T>>43/**44*45* @deprecated This function will be removed in future version.46*47* Note: If you are using Vue 3.4+, you can straight use computed instead.48* Because in Vue 3.4+, if computed new value does not change,49* computed, effect, watch, watchEffect, render dependencies will not be triggered.50* refer: https://github.com/vuejs/core/pull/591251*52* @param fn effect function53* @param options WatchOptionsBase54* @returns readonly shallowRef55*/56export declare function computedEager<T>(57fn: () => T,58options?: ComputedEagerOptions,59): ComputedEagerReturn<T>60/** @deprecated use `computedEager` instead */61export declare const eagerComputed: typeof computedEager62```63