Dummy User
Dummy User

Reputation: 29

Vue 3 computed keyword (Composition API)

Tmp Object looks like :

tmp : { k1: { k2 : { k3 : [abc, def] } }

Accessing k3 in setup looks like

tmp.value.k1.k2.k3[0 or 1].

I want to rename it to something like -

k3_arr = tmp.value.k1.k2.k3;

Inside my Vue single component setup function:

const tmp = (getting value from composable exported using ...toRefs from there)

// Already tried 1

const d = reactive({
         k3_arr : computed(() => { tmp.value.k1.k2.k3; }
}

return { ...toRefs(d) }


// Already tried 2 
const k3_arr = computed(() => { tmp.value.k1.k2.k3; }
return { k3_arr }

None of this is working.

Upvotes: 1

Views: 645

Answers (1)

Estus Flask
Estus Flask

Reputation: 223249

There are mistakes in listed computed properties. A value isn't returned from arrow function. There is no need to create reactive only to convert it back with toRefs.

It should be:

const k3_arr = computed(() => tmp.value.k1.k2.k3);

Upvotes: 1

Related Questions