'Create a deconstructed computed properties out of a computed object

In my vue component, I have a computed object which I wanted to deconstruct.

const profile_state = computed(() => store.getters['profile/GET_STATE']);

Since there are too many properties that I need to access, I don't want to create them one by one.

Is it possible to have a deconstructed computed properties? Something like this:

const { name, address, phone, city, token } = computed(() => profile_state);


Solution 1:[1]

I just ran into this same scenario and confirmed you definitely can deconstruct computed values. The only extra step required is adding ".value" to the end of your computed function call.

e.g. in this case:

const { name, address, phone, city, token } = computed(() => profile_state).value;

As without this the parent object isn't being accessed and deconstructed in the assignment as expected.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tw-dev