vuejs / vue-class-component

ES / TypeScript decorator for class-style Vue components.
MIT License
5.81k stars 429 forks source link

vue-class-component declares unmounted method despite being compatible with Vue 2 #578

Open lucaswerkmeister opened 2 years ago

lucaswerkmeister commented 2 years ago

vue-class-component 7.2.4 added a dist/vue-class-component.d.ts file with an interface ClassComponentHooks which defines an optional unmounted() method. However, in Vue 2 this lifecycle hook is actually called destroyed() (it’s renamed to unmounted() in Vue 3), and as far as I can tell, vue-class-component has no special code to translate between the two names. In this jsfiddle, only the destroyed() method is called.

suterma commented 1 year ago

To highlight this: when using vue2 (2.7.14 in my case), in only works when using destroyed. Thus, the existence of the unmounted function can be misleading for vue3-used developers working on older code.

This works in Vue2:

destroyed(): void {
    console.debug('destroyed');
}

This does NOT WORK in Vue2, although no compilation or runtime error is thrown:

# Does not work wiht Vue2!!
unmounted(): void {
    console.debug('Office::unmounted');
}