vue-lynx / computed

Function: computed()

computed(getter, debugOptions)

function computed<T>(getter, debugOptions?): ComputedRef<T>

Takes a getter function and returns a readonly reactive ref object for the returned value from the getter. It can also take an object with get and set functions to create a writable ref object.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
getterComputedGetter<T>Function that produces the next value.
debugOptions?DebuggerOptionsFor debugging. See https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging.

Returns

ComputedRef<T>

Example

// Creating a readonly computed ref:
const count = ref(1)
const plusOne = computed(() => count.value + 1)

console.log(plusOne.value) // 2
plusOne.value++ // error
// Creating a writable computed ref:
const count = ref(1)
const plusOne = computed({
  get: () => count.value + 1,
  set: (val) => {
    count.value = val - 1
  }
})

plusOne.value = 1
console.log(count.value) // 0

See

https://vuejs.org/api/reactivity-core.html#computed

Defined in

node_modules/.pnpm/@vue+runtime-core@3.5.30/node_modules/@vue/runtime-core/dist/runtime-core.d.ts:6

computed(options, debugOptions)

function computed<T, S>(options, debugOptions?): WritableComputedRef<T, S>

Type Parameters

Type ParameterDefault type
T-
ST

Parameters

ParameterType
optionsWritableComputedOptions<T, S>
debugOptions?DebuggerOptions

Returns

WritableComputedRef<T, S>

Defined in

node_modules/.pnpm/@vue+runtime-core@3.5.30/node_modules/@vue/runtime-core/dist/runtime-core.d.ts:6