panzerdp / dmitripavlutin.com-comments

7 stars 0 forks source link

props-destructure-vue-composition/ #158

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

How to Destructure Props in Vue (Composition API)

How to correctly destructure props object in a Vue component while maintaining the reactivity.

https://dmitripavlutin.com/props-destructure-vue-composition/

VerVera commented 1 year ago

One more solution. Continue use vue option api

panzerdp commented 1 year ago

One more solution. Continue use vue option api

Could be a good option, if that's your preference. 😄

Demivan commented 1 year ago

By the way you can enable Reactivity Transform to preserve reactivity when props are destructured. Even with Reactivity Transform being dropped, Reactive Props Destructure part will most likely be kept.

panzerdp commented 1 year ago

By the way you can enable Reactivity Transform to preserve reactivity when props are destructured

That's a good idea, thanks for suggesting it @Demivan.

But please note that the Reactivity Transform is now deprecated.

Demivan commented 1 year ago

@panzerdp Yes, but here https://youtu.be/OrT0tHGXyqE?t=1094 Evan says that Reactive Props Destructure will be split from Reactivity Transform and will likely land.

It just provides so much nicer syntax for Typescript users.

panzerdp commented 1 year ago

@Demivan That's wonderful news! It's a needed feature.

wvovaw commented 1 year ago

Here it is! The Vue 3.3 release brings us another way of destructuring props while keeping them reactive. It also gives a nifty syntax for assigning default values