Skip to content

event.off is not removing the event #123

Closed
@bci24

Description

It seems that off is not working or I am missing something.

I am using mitt it in Vue 3

`import mitt from "mitt";
const Event = mitt();

const app = createApp(App);
app.config.globalProperties.Event = Event;
app.mount('#app');`

I have 2 components Category and CategoryDetails and when changing from one to another it seems that the off is not "destroying" the event.

In CategoryDetails component:

mounted() { const vm = this; this.Event.on('category.save', function(){ vm.formSubmit(); }); },

// it should clear the event - to no longer emit
unmounted() { this.Event.off('category.save'); }

Entering again in CateegoryDetails and emits the save, it make 2 request and so on....

I have tried to use in unmounted:

this.Event.all.clear();

and seems to work.

Why is not working if I specify the event name to off ???

Am i missing something ?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions