vue-property-decorator icon indicating copy to clipboard operation
vue-property-decorator copied to clipboard

feat: Added @Setup() decorator for usage with the composition API.

Open michealroberts opened this issue 3 years ago • 6 comments

feat: Added @Setup() decorator for usage with the composition API.

Includes associated test suite for expected output.

Includes upgrades to the underlying "vue" and "vue-template-compiler" package versions => 2.7.5.

michealroberts avatar Jul 13 '22 12:07 michealroberts

What is the use of this particular decorator?

Although this decorator mixes two paradigms, e.g., class-based-components and the composition API, this may help teams to migrate from class-based-components by allowing usage of the composition API within class based components. I think there could be a strong need for this as teams migrate legacy Vue 2 typescript stacks to Vue 3.

michealroberts avatar Jul 13 '22 12:07 michealroberts

👍

astraios avatar Jul 18 '22 10:07 astraios

@kaorun343 Any thoughts on this PR?

michealroberts avatar Jul 25 '22 08:07 michealroberts

I think writing setup function in Component decorator is enough and the new decorator is not needed.

kaorun343 avatar Jul 25 '22 08:07 kaorun343

I think writing the setup function in the Component decorator is enough and the new decorator is not needed.

Don't you think having the setup in components declaration in the class leaves unnecessary entropy (especially for huge projects who have to migrate to composition gradually) between code inside/outside setup:

image

I dunno, but I feel the proposed idea is better. also, it's very unusual at least for me to have the setup inside the Component decorator, then the class declaration followed by the class code.

eugeniomachadoi avatar Jul 26 '22 14:07 eugeniomachadoi

You can use registerHooks instead of this @Setup decorator.

https://class-component.vuejs.org/guide/additional-hooks.html

Also, allowing setup function as a n instance method may causes invalid this access. This is why @Filter decorator is not included to this library.

kaorun343 avatar Jul 26 '22 22:07 kaorun343