Home  >  Q&A  >  body text

Replacement of "emit" method in Vue

When I use "emit", Vue complains that I'm looking for a functionally equivalent alternative

This will be a to-do list

Code:

Warning in browser console:

runtime-core.esm-bundler.js?5c40:38 [Vue warn]: An unrelated non-emitted event listener (deleteTodoEvent) was passed to the component but cannot be automatically inherited because the component renders a fragment or text root node . If the listener is to be used only as a component custom event listener, declare it using the "emis" option. at > at

P粉668019339P粉668019339213 days ago305

reply all(1)I'll reply

  • P粉178132828

    P粉1781328282024-03-20 13:18:03

    You appear to be using Vue 3. The warning tells you that the event is not declared before it is used in the component. Here is an example:

    export default {
      name: "YourComponent",
      emits: ["deleteTodoEvent"], // <--- this is what the warning in hinting to
      setup(_,{ emit }) {
        ...
      },
    };

    reply
    0
  • Cancelreply