vue-class-component icon indicating copy to clipboard operation
vue-class-component copied to clipboard

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

Open lucaswerkmeister opened this issue 4 years ago • 1 comments

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.

lucaswerkmeister avatar Nov 25 '21 16:11 lucaswerkmeister

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');
}

suterma avatar May 09 '23 14:05 suterma