• The hook version of computed from @vue/reactivity.

    This hook version allows the computed ref to be created when the component first renders, then cached for future re-renders.


    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.

    Example

    // Inside a function component:
    // Creating a readonly computed ref:
    const count = useRef(1)
    const plusOne = useComputed(() => count.value + 1)

    console.log(plusOne.value) // 2
    plusOne.value++ // error

    Example

    // Inside a function component:
    // Creating a writable computed ref:
    const count = useRef(1)
    const plusOne = useComputed({
    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

    Type Parameters

    • T

    Parameters

    Returns ComputedRef<T>

  • The hook version of computed from @vue/reactivity.

    This hook version allows the computed ref to be created when the component first renders, then cached for future re-renders.


    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.

    Example

    // Inside a function component:
    // Creating a readonly computed ref:
    const count = useRef(1)
    const plusOne = useComputed(() => count.value + 1)

    console.log(plusOne.value) // 2
    plusOne.value++ // error

    Example

    // Inside a function component:
    // Creating a writable computed ref:
    const count = useRef(1)
    const plusOne = useComputed({
    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

    Type Parameters

    • T

    Parameters

    Returns WritableComputedRef<T>

Generated using TypeDoc