1

I'm wondering where it's correct to use .value when referencing reactive objects if they are nested 2+ levels deep. Do you put .value on the base object and then access sub-keys off that? Or do you put it on the deepest key?

Here is an example:

import { reactive, computed } from 'vue'

const someObj = reactive({
    a: {
        b: {
            c: 1
        }
    }
})

const doubleSomeObj = computed(() => {
    return someObj.value.a.b.c * 2
    // Or... someObj.a.b.c.value * 2
    // Or something else?
})

In the above code, in the computed property doubleSomeObj, it references the nested object someObj.

When referencing the various keys in that nested object someObj, at what level is it correct to put .value?

1 Answer 1

3

.value is only used on refs. The reactive object's subproperties can be used without employing .value, so you could just directly multiply it in your computed prop:

const doubleSomeObj = computed(() => {
    return someObj.a.b.c * 2
})

demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.