fn
computedEager
v0.0.15testeddemoEager (non-lazy) computed value backed by a `watchEffect`-driven `shallowRef`. Unlike `computed`, the getter runs immediately and on every dependency change rather than lazily on read, so the cached value is always up to date. Best for cheap derived values that are read in many places.
Examples
ts
const count = ref(0);
const isEven = computedEager(() => count.value % 2 === 0);
isEven.value; // truets
// Defer recomputation until after the component update flush
const total = computedEager(() => a.value + b.value, { flush: 'post' });Demo
Loading demo…
Signature
ts
export function computedEager<T>(getter: () => T, options: ComputedEagerOptions ={ ... }Type Parameters
TParameters
| Parameter | Type | Description |
|---|---|---|
getter | () => T | The effect function deriving the value |
options? | ComputedEagerOptions | Watch options (`flush` defaults to `'sync'`) |
Returns
Readonly<ShallowRef<T>>A readonly shallow ref holding the derived value