computed() — vue Function Reference
Architecture documentation for the computed() function in computed.ts from the vue codebase.
Entity Profile
Dependency Diagram
graph TD df07630f_4e3a_2f93_4e01_6cb85723b456["computed()"] d0456733_d7ef_e7d5_e71b_f85674bc99f2["evaluate()"] df07630f_4e3a_2f93_4e01_6cb85723b456 -->|calls| d0456733_d7ef_e7d5_e71b_f85674bc99f2 b6fb2fe6_1e20_8aa7_252b_c7c3e62b0e26["depend()"] df07630f_4e3a_2f93_4e01_6cb85723b456 -->|calls| b6fb2fe6_1e20_8aa7_252b_c7c3e62b0e26 style df07630f_4e3a_2f93_4e01_6cb85723b456 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/v3/reactivity/computed.ts lines 37–100
export function computed<T>(
getterOrOptions: ComputedGetter<T> | WritableComputedOptions<T>,
debugOptions?: DebuggerOptions
) {
let getter: ComputedGetter<T>
let setter: ComputedSetter<T>
const onlyGetter = isFunction(getterOrOptions)
if (onlyGetter) {
getter = getterOrOptions
setter = __DEV__
? () => {
warn('Write operation failed: computed value is readonly')
}
: noop
} else {
getter = getterOrOptions.get
setter = getterOrOptions.set
}
const watcher = isServerRendering()
? null
: new Watcher(currentInstance, getter, noop, { lazy: true })
if (__DEV__ && watcher && debugOptions) {
watcher.onTrack = debugOptions.onTrack
watcher.onTrigger = debugOptions.onTrigger
}
const ref = {
// some libs rely on the presence effect for checking computed refs
// from normal refs, but the implementation doesn't matter
effect: watcher,
get value() {
if (watcher) {
if (watcher.dirty) {
watcher.evaluate()
}
if (Dep.target) {
if (__DEV__ && Dep.target.onTrack) {
Dep.target.onTrack({
effect: Dep.target,
target: ref,
type: TrackOpTypes.GET,
key: 'value'
})
}
watcher.depend()
}
return watcher.value
} else {
return getter()
}
},
set value(newVal) {
setter(newVal)
}
} as any
def(ref, RefFlag, true)
def(ref, ReactiveFlags.IS_READONLY, onlyGetter)
return ref
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does computed() do?
computed() is a function in the vue codebase.
What does computed() call?
computed() calls 2 function(s): depend, evaluate.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free