getyourguide / vue-class-migrator

Vue 3 Migration helper for applications using Vue 2.7
Apache License 2.0
57 stars 19 forks source link

fix: missing vue special method #169

Open barnett617 opened 1 month ago

barnett617 commented 1 month ago

First, thanks for this project for helping old projects' migration ♥️. I got a bug while using this project to migrate my project because there has some code like below:

@Component
export default class Test extends Vue {
    created() {
        document.addEventListener('mousedown', onMousedown);
    }
    onMousedown() {
        console.log('mousedown');
    }
    beforeDestroy() {
        document.removeEventListener('mousedown', onMousedown);
    }
}

this code was migrated into below:

import { defineComponent } from "vue";

export default defineComponent({
    created() {
        document.addEventListener('mousedown', onMousedown);
    },
    methods() {
        onMousedown() {
            console.log('mousedown');
        },
        beforeDestroy() {
            document.removeEventListener('mousedown', onMousedown);
        }
    }
})

This will miss the event unregister after the component destroyed because the special method "beforeDestroy" was incorrectly migrated into methods. It cause unexpected event handles in my project.

So I create this PR to fix this bug about "beforeDestroy" using.