We are using Vue 2 with a lot of components built on top of class based components using vue-class-component and vue-property-decorator.

Now we need to upgrade to Vue 3 for better performance and long time support.

To answer your questions:

  1. I did a lot of research and there is no plan to support class based components going forward from here. The two plugins from above are stuck at RC level for Vue 3. See: https://github.com/vuejs/vue-class-component/issues/406

  2. A library which is not maintained and/or properly tested with a new Version of Vue is never a good idea to use imo.

  3. Thats a question where there is no clear answer for.

You can try this strategy, maybe it works for you too:

We added the composition API and script setup via these plugins to our existing Vue 2 code base:

  • https://github.com/vuejs/composition-api
  • https://github.com/antfu/unplugin-vue2-script-setup

Update 22/07/10: Vue 2.7 (the last minor release) was released, there is no need for the plugins above when using this version: https://blog.vuejs.org/posts/vue-2-7-naruto.html

This allows us to use composition API + script setup and class based components simultaneously. So we are beginning to write new components with the new syntax and rewriting old code step by step. When we are done with this process, we are going to migrate to Vue 3 using the migration guide:

  • https://v3-migration.vuejs.org/

That is a lot of work and very annoying to do, as it takes a lot of time away from new features or bugfixes which are more important than dealing with this upgrade pain. But we hope going forward from here that Vue is going to me more stable in their decisions and how they want to continue forward.

I also agree with you saying that class based components are a more elegant way to do things than the composition API. It is also shorter and closer to backend programming languages. Its very sad to see this one go.

All the best Jakob

Update 23/04/14: Great new article on how one could continue using class based components: https://medium.com/@robert.helms1/vue-2-to-vue-3-with-class-components-cdd6530a2b2a

Further ressources:

Guide: https://levelup.gitconnected.com/from-vue-class-component-to-composition-api-ef3c3dd5fdda

More reasons why they drop it:

https://github.com/vuejs/rfcs/pull/17#issuecomment-494242121

https://github.com/vuejs/rfcs/blob/function-apis/active-rfcs/0000-function-api.md#type-issues-with-class-api

https://vuejs.org/guide/extras/composition-api-faq.html#better-type-inference

Answer from JBS on Stack Overflow
🌐
GitHub
github.com › kaorun343 › vue-property-decorator
GitHub - kaorun343/vue-property-decorator: Vue.js and Property Decorator · GitHub
February 7, 2024 - If you still want to use classes, check out the community-maintained project vue-facing-decorator. This library fully depends on vue-class-component, so please read its README before using this library. ... import { Vue, Component, Prop } from 'vue-property-decorator' @Component export default class YourComponent extends Vue { @Prop(Number) readonly propA: number | undefined @Prop({ default: 'default value' }) readonly propB!: string @Prop([String, Boolean]) readonly propC: string | boolean | undefined }
Starred by 5.5K users
Forked by 377 users
Languages   TypeScript 86.7% | JavaScript 13.3%
🌐
GitHub
github.com › kaorun343 › vue-property-decorator › issues › 294
kaorun343/vue-property-decorator
January 5, 2020 - kaorun343 / vue-property-decorator Public archive · Notifications · You must be signed in to change notification settings · Fork 376 · Star 5.5k · Copy link · Copy link · Closed · Closed · Vue 3.0 support#294 · Copy link · Labels · vue3.0 · avxkim · opened ·
Author   avxkim
Top answer
1 of 4
18

We are using Vue 2 with a lot of components built on top of class based components using vue-class-component and vue-property-decorator.

Now we need to upgrade to Vue 3 for better performance and long time support.

To answer your questions:

  1. I did a lot of research and there is no plan to support class based components going forward from here. The two plugins from above are stuck at RC level for Vue 3. See: https://github.com/vuejs/vue-class-component/issues/406

  2. A library which is not maintained and/or properly tested with a new Version of Vue is never a good idea to use imo.

  3. Thats a question where there is no clear answer for.

You can try this strategy, maybe it works for you too:

We added the composition API and script setup via these plugins to our existing Vue 2 code base:

  • https://github.com/vuejs/composition-api
  • https://github.com/antfu/unplugin-vue2-script-setup

Update 22/07/10: Vue 2.7 (the last minor release) was released, there is no need for the plugins above when using this version: https://blog.vuejs.org/posts/vue-2-7-naruto.html

This allows us to use composition API + script setup and class based components simultaneously. So we are beginning to write new components with the new syntax and rewriting old code step by step. When we are done with this process, we are going to migrate to Vue 3 using the migration guide:

  • https://v3-migration.vuejs.org/

That is a lot of work and very annoying to do, as it takes a lot of time away from new features or bugfixes which are more important than dealing with this upgrade pain. But we hope going forward from here that Vue is going to me more stable in their decisions and how they want to continue forward.

I also agree with you saying that class based components are a more elegant way to do things than the composition API. It is also shorter and closer to backend programming languages. Its very sad to see this one go.

All the best Jakob

Update 23/04/14: Great new article on how one could continue using class based components: https://medium.com/@robert.helms1/vue-2-to-vue-3-with-class-components-cdd6530a2b2a

Further ressources:

Guide: https://levelup.gitconnected.com/from-vue-class-component-to-composition-api-ef3c3dd5fdda

More reasons why they drop it:

https://github.com/vuejs/rfcs/pull/17#issuecomment-494242121

https://github.com/vuejs/rfcs/blob/function-apis/active-rfcs/0000-function-api.md#type-issues-with-class-api

https://vuejs.org/guide/extras/composition-api-faq.html#better-type-inference

2 of 4
4

FWIW, despite the fact that I am really more a fan of using class based components, we made the decision to convert all our ±300 components to Options API. So at least we can upgrade to Vue@3 and Vite. Changing the complete codebase to Composition API (with <script setup>) is not worth it and potentially error prone. All new components will be written with <script setup> though.

Steps that we followed to get there:

  1. Make sure you are at [email protected]. This version includes backported features from vue@3, including Composition API and <script setup>. See their blog.
  2. Check and update all dependencies to be compatible with [email protected] (e.g. we make extensive use of AgGrid that needed to be at version 27).
  3. Gradually convert all class components to Options API via this package: https://www.npmjs.com/package/vue-declassify. (Only the @Emit decorator needs to be handled manually). cd into a directory that you want to convert and run this command: find . -name "*.vue" -exec vue-declassify {} \; to execute the converted on multiple vue files sequentially.

This process took us approximately 2 days to execute completely.

NB: Make sure that your codebase is thoroughly backed by unit and e2e tests prior starting this process .

🌐
LogRocket
blog.logrocket.com › home › define properties with vue property decorator and typescript
Define properties with Vue Property Decorator and TypeScript - LogRocket Blog
June 4, 2024 - Define properties like data, methods, and watchers directly on the class in Vue components with Vue Property Decorator and TypeScript.
🌐
npm
npmjs.com › package › vue-property-decorator › v › 10.0.0-rc.3
vue-property-decorator - npm
March 9, 2021 - property decorators for Vue Component. Latest version: 9.1.2, last published: 5 years ago. Start using vue-property-decorator in your project by running `npm i vue-property-decorator`. There are 2890 other projects in the npm registry using vue-property-decorator.
      » npm install vue-property-decorator
    
Published   Nov 20, 2020
Version   10.0.0-rc.3
Author   kaorun343
🌐
Davidjamesherzog
davidjamesherzog.github.io › 2020 › 12 › 30 › vue-typescript-decorators
Vue.js with Typescript and Decorators | David Herzog
December 29, 2020 - Here is a list of libraries we will be adding: vue-class-component (opens new window) - used to define components which is installed by default when Typescript Vue 3 project created · vue-property-decorator (opens new window) - used to define props, watches, etc.
🌐
DEV Community
dev.to › wormss › comment › 11pl9
And if you are using vue-property-decorator? — DEV Community
July 12, 2020 - import { Component, Ref, Watcher, Vue } from 'vue-property-decorator'; import NestedComponent from './NestedComponent'; @Component({ components: { NestedComponent }}) export default class MyClass extends Vue { @Ref() private someRef?: HTMLInputElement; private someData: string; private someComputed(): string { return window.localStorage.getItem('foobar') ??
🌐
Packtpub
subscription.packtpub.com › book › web_development › 9781838826222 › 2 › ch02lvl1sec09 › adding-vue-property-decorator-to-vue-class-component
Adding vue-property-decorator to vue-class-component
Some of the most important parts of Vue are missing in the vue-class-component in the form of TypeScript decorators. So, the community made a library called vue-property-decorator that is fully endorsed by the Vue core team.
🌐
Vuejs
class-component.vuejs.org › guide › custom-decorators.html
Custom Decorators | Vue Class Component
// decorators.js import { createDecorator } from 'vue-class-component' // Declare Log decorator. export const Log = createDecorator((options, key) => { // Keep the original method for later. const originalMethod = options.methods[key] // Wrap the method with the logging logic. options.methods[key] = function wrapperMethod(...args) { // Print a log. console.log(`Invoked: ${key}(`, ...args, ')') // Invoke the original method. originalMethod.apply(this, args) } }) ... import Vue from 'vue' import Component from 'vue-class-component' import { Log } from './decorators' @Component class MyComp extends Vue { // It prints a log when `hello` method is invoked.
Find elsewhere
🌐
Medium
medium.com › @1234and95 › vue-2-to-vue-3-class-component-property-decorator-migration-guide-9b9e451f7527
Vue 2 to Vue 3 class component(property decorator) Migration Guide - And - Medium
December 6, 2024 - "vuex": "^4.1", "vuex-module-decorators": "^1.0.1" Vue 2: import { Component, Vue } from 'vue-property-decorator' import { namespace } from 'vuex-class' const someStore = namespace('someStore') @Component({}) export default class Component1 extends Vue {} Vue 3: import { Component, Vue } from 'vue-facing-decorator' import { namespace } from 'vuex-facing-decorator' const someStore = namespace('someStore') @Component({}) export default class Component1 extends Vue {} https://v3-migration.vuejs.org/ Documentation: https://facing-dev.github.io/vue-facing-decorator/#/ Vue 2 ·
🌐
Vuejs
class-component.vuejs.org
Overview | Vue Class Component
<template> <div> <button v-on:click="decrement">-</button> {{ count }} <button v-on:click="increment">+</button> </div> </template> <script> import Vue from 'vue' import Component from 'vue-class-component' // Define the component in class-style @Component export default class Counter extends Vue { // Class properties will be component data count = 0 // Methods will be component methods increment() { this.count++ } decrement() { this.count-- } } </script> As the example shows, you can define component data and methods in the intuitive and standard class syntax by annotating the class with the @Component decorator.
🌐
npm
npmjs.com › package › vue-decorator
vue-decorator - npm
May 8, 2021 - This give us custom decorators provide by vue-class-component and vue-property-decorator that fits Vue 3 · ##Compatible: Vue 3 · yarn add vue-decorator · npm i vue-decorator · vue · vue3 · typescript · decorator · npm i vue-decorator · github.com/calebeaires/vue-decorator ·
      » npm install vue-decorator
    
Published   May 08, 2021
Version   1.1.3
Author   calebeaires
🌐
GitHub
github.com › kaorun343 › vue-property-decorator › issues › 283
Is Vue3 supported? · Issue #283 · kaorun343/vue-property-decorator
November 24, 2019 - kaorun343 / vue-property-decorator Public archive · Notifications · You must be signed in to change notification settings · Fork 378 · Star 5.5k · This repository was archived by the owner on Feb 7, 2024. It is now read-only. Copy link · Copy link · Closed · Closed · Is Vue3 supported?#283 ·
🌐
DEV Community
dev.to › metal3d › vue-ts-without-class-component-no-way-ic3
Vue + TS without class component ? No way! - DEV Community
September 15, 2022 - There is a fantastic module named vue-facing-decorator here: https://facing-dev.github.io/vue-facing-decorator/ Designed for vue 3, do the same work like vue-class-component and vue-property-decorator.
🌐
CodeSandbox
codesandbox.io › examples › package › vue-property-decorator
vue-property-decorator examples - CodeSandbox
Aboutproperty decorators for Vue Component329,212Weekly Downloads · Latest version9.1.2 · LicenseMIT · External Links · github.com/kaorun343/vue-property-decorator#readme · github.com/kaorun343/vue-property-decorator · github.com/kaorun343/vue-property-decorator/issues ·
🌐
UNPKG
app.unpkg.com › vue-property-decorator@7.3.0 › files › lib › vue-property-decorator.d.ts
vue-property-decorator
/** vue-property-decorator verson 7.3.0 MIT LICENSE copyright 2018 kaorun343 */ import Vue, { PropOptions, WatchOptions } from 'vue'; import Component, { mixins } from 'vue-class-component'; import { InjectKey } from 'vue/types/options'; export declare type Constructor = { new (...args: any[]): any; }; export { Component, Vue, mixins as Mixins }; /** * decorator of an inject * @param from key * @return PropertyDecorator */ export declare function Inject(options?: { from?: InjectKey; default?: any; } | InjectKey): PropertyDecorator; /** * decorator of a provide * @param key key * @return Proper
🌐
Lightrun
lightrun.com › answers › vuejs-vue-class-component-vue-v3-changes-for-component-decorator-and-vue-base-class
[Vue v3] Changes for @Component decorator and Vue base class
Define properties like data, methods, and watchers directly on the class in Vue components with Vue Property Decorator and TypeScript.Read more >
🌐
Pocket Prep
pocketprep.com › home › dealing with class components: vue 2 to vue 3
Dealing with Class Components: Vue 2 to Vue 3 - Pocket Prep
November 13, 2023 - The real answer (spoiler alert) is that we finally found a replacement package to allow our existing class components to continue working in Vue 3: vue-facing-decorator.
🌐
Stack Overflow
stackoverflow.com › questions › tagged › vue-property-decorator
Newest 'vue-property-decorator' Questions - Stack Overflow
When I only use Jest with Vue project, I can't import subcomponent in component, if I do according to tips, also I cannot define private variable the reproduce project :jest-decorator-issue also can ... ... my stacks are Nuxtjs and Nuxt-property-decorator I've made a mixin to avoid repeating a method that method need a component ( Alert component ) so , I imported that component in mixin But i have error ...