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%
🌐
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.
Discussions

vuejs2 - Migrating from vue2 with property-decorator and class style syntax to vue3 - Stack Overflow
I maintain quite a large vue2 project, which among other libraries makes use of Vuetify, vue-class-component, vue-property-decorator and typescript. Example component: (The component is simplified... More on stackoverflow.com
🌐 stackoverflow.com
Newest 'vue-property-decorator' Questions - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers More on stackoverflow.com
🌐 stackoverflow.com
Vue 3.0 support
Vue.js and Property Decorator. Contribute to kaorun343/vue-property-decorator development by creating an account on GitHub. More on github.com
🌐 github.com
93
January 5, 2020
typescript - @model decorator from vue-property-decorator generates vue-warn: Avoid mutating - Stack Overflow
I use typescript with this lib. And I have following code in file HomePage.vue : Write something x: More on stackoverflow.com
🌐 stackoverflow.com
🌐
npm
npmjs.com › package › vue-property-decorator
vue-property-decorator - npm
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 2885 other projects in the npm registry using vue-property-decorator.
      » npm install vue-property-decorator
    
Published   Nov 20, 2020
Version   9.1.2
Author   kaorun343
🌐
Vuejs
class-component.vuejs.org › guide › custom-decorators.html
Custom Decorators | Vue Class Component
Vue Class Component provides ... custom decorators. createDecorator expects a callback function as the 1st argument and the callback will receive following arguments: options: Vue component options object. Changes for this object will affect the provided component. key: The property or method ...
🌐
egghead.io
egghead.io › lessons › vue-js-define-props-on-a-vue-class-with-vue-property-decorator
Define Props on a Vue Class with vue-property-decorator | egghead.io
vue-property-decorator allows you to define your properties directly on your class with a simple @Prop() decorator. This approach allows your classes to...
Published   December 13, 2017
🌐
npm
npmjs.com › search
vue-property-decorator - npm search
Vue typescript class and decorator based component. ... ruojianll• 4.0.1 • 6 months ago • 28 dependents • MITpublished version 4.0.1, 6 months ago28 dependents licensed under $MIT ... [![npm](https://img.shields.io/npm/v/vue-property-decorator.svg)](https://www.npmjs.com/package/vue-property-decorator) [![Build Status](https://travis-ci.org/kaorun343/vue-property-decorator.svg?branch=master)](https://travis-ci.org/kaorun343/vue-proper
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 .

🌐
GitHub
github.com › dhlim-dev › vue-property-decorator
GitHub - dhlim-dev/vue-property-decorator: Vue.js and Property Decorator · GitHub
import { Component, Emit, Inject, Model, Prop, Provide, Vue, Watch } from 'vue-property-decorator' const s = Symbol('baz') @Component export class MyComponent extends Vue { @Emit() addToCount(n: number){ this.count += n } @Emit('reset') resetCount(){ this.count = 0 } @Inject foo: string @Inject('bar') bar: string @Inject(s) baz: string @Model('change') checked: boolean @Prop propA: number @Prop('default value') propB: string @Prop([String, Boolean]) propC: string | boolean @Prop({ type: null }) propD: any @Provide foo = 'foo' @Provide('bar') baz = 'bar' @Watch('child') onChildChanged(val: string, oldVal: string) { } @Watch('person', { immediate: true, deep: true }) onPersonChanged(val: Person, oldVal: Person) { } }
Author   dhlim-dev
Find elsewhere
🌐
Snyk
snyk.io › advisor › vue-property-decorator › functions › vue-property-decorator.prop
How to use the vue-property-decorator.Prop function in vue-property-decorator | Snyk
import Vue from 'vue'; import { Component, Prop } from 'vue-property-decorator'; import { AppTooltip } from '../../../tooltip/tooltip'; @Component({ directives: { AppTooltip, }, }) export default class AppBaseContentComponent extends Vue { @Prop(Boolean) isEditing!: boolean; @Prop(Boolean) showEdit!: boolean; @Prop(Boolean) isDisabled!: boolean; onRemovedClicked() { if (!this.isDisabled) { this.$emit('removed'); } } onEditClicked() { if (!this.isDisabled) { this.$emit('edit'); } }
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › tagged › vue-property-decorator
Newest 'vue-property-decorator' Questions - Stack Overflow
I'm writing application using Vue 2/typescript and vue-property-decorator. In my component I use beforeRouteEnter/beforeRouteUpdate hooks.
🌐
GitHub
github.com › kaorun343 › vue-property-decorator › issues › 294
kaorun343/vue-property-decorator
January 5, 2020 - Vue.js and Property Decorator. Contribute to kaorun343/vue-property-decorator development by creating an account on GitHub.
Author   avxkim
🌐
Reintech
reintech.io › term › vue-property-decorator
vue-property-decorator: TypeScript Decorators for Vue.js Components | Reintech media
vue-property-decorator is a TypeScript library that provides decorators for working with Vue.js components. It builds on top of the official vue-class-component package and helps simplify the process of creating and managing Vue.js components ...
🌐
Snyk
snyk.io › advisor › javascript packages › vue-property-decorator
vue-property-decorator - npm Package Health Analysis | Snyk
October 4, 2020 - Learn more about vue-property-decorator: package health score, popularity, security, maintenance, versions and more.
🌐
CodeSandbox
codesandbox.io › examples › package › vue-property-decorator
vue-property-decorator examples - CodeSandbox
Use this online vue-property-decorator playground to view and fork vue-property-decorator example apps and templates on CodeSandbox.
🌐
Tessl
tessl.io › registry › tessl › npm-vue-property-decorator
9.1.0 • npm-vue-property-decorator
TypeScript decorators for Vue.js class-based components with property binding, state management, and lifecycle capabilities
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Vue Property Decorator Snippets - Visual Studio Marketplace
Extension for Visual Studio Code - Usefull snippets to work with decorators in Vue and typescript files
🌐
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') ??
Top answer
1 of 3
7

TL:DR

I'm new in Vue (coming from React) but from what I understand the answer above is not wrong but it doesn't answer the question of how to use @Model decorator. Provide and Inject is an overkill for passing props from parent to child. The documentation is not clear, so I scratched my head a lot on this one. But remember that the package is referring to props. Hence @Prop, @PropSync and @Model should be at the child component. Here is what I did and it didn't throw out that horrible console error. Parent component:

<template>
  <div>
     <input type="text" v-model="modelText" />
    <Child 
      :modelText="modelText"
    />
  </div>
</template>

<script lang="ts">
import Component from 'vue-class-component';
import Vue from 'vue';
import Child from './Child.vue';

@Component({
  components: {
    Child,
  }
})
export default class Parent extends Vue {
  private modelText: string = 'model-text';
}
</script>

And for the child component:

<template>
    <div>
      @Model: {{modelText}}
    </div>
</template>

<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop, PropSync, Model } from 'vue-property-decorator';

@Component({

})
export default class Child extends Vue {
  @Model('input', { type: String }) modelText!: string;
}
</script>
2 of 3
5

Since v. 9.1.2 view-property-decorator now supports the @VModel decorator.

Where

import { Vue, Component, VModel } from 'vue-property-decorator'

@Component
export default class CustomComponent extends Vue {
  @VModel() name!: string
}

will make it possible to use two-way-databinding with name inside the component and v-model="..." from the outside. Without the annoying warnings!

https://github.com/kaorun343/vue-property-decorator#-vmodelpropsargs-propoptions-decorator

🌐
Npm
npm.io › package › vue-property-decorator
Vue-property-decorator NPM | npm.io
The functions decorated by @Emit $emit their return value followed by their original arguments. If the return value is a promise, it is resolved before being emitted. If the name of the event is not supplied via the event argument, the function name is used instead. In that case, the camelCase name will be converted to kebab-case. import { Vue, Emit } from 'vue-property-decorator' export default class YourComponent extends Vue { count = 0 @Emit() addToCount(n: number) { this.count += n } @Emit('reset') resetCount() { this.count = 0 } @Emit() returnValue() { return 10 } @Emit() onInputChange(e) { return e.target.value } @Emit() promise() { return new Promise((resolve) => { setTimeout(() => { resolve(20) }, 0) }) } }